@@ -40,9 +40,16 @@ static GLuint compile_gl_shader(GLenum type, const std::string &name, const std:
40
40
if (shader_string.empty ())
41
41
return (GLuint)0 ;
42
42
43
- GLuint id = glCreateShader (type);
44
- const char *shader_string_const = shader_string.c_str ();
45
- CHK (glShaderSource (id, 1 , &shader_string_const, nullptr ));
43
+ GLuint id;
44
+ CHK (id = glCreateShader (type));
45
+ const GLchar *files[] = {
46
+ #ifdef __EMSCRIPTEN__
47
+ " #version 300 es\n " ,
48
+ #else
49
+ " #version 330 core\n " ,
50
+ #endif
51
+ shader_string.c_str ()};
52
+ CHK (glShaderSource (id, 2 , files, nullptr ));
46
53
CHK (glCompileShader (id));
47
54
48
55
GLint status;
@@ -73,17 +80,6 @@ static GLuint compile_gl_shader(GLenum type, const std::string &name, const std:
73
80
return id;
74
81
}
75
82
76
- // Hack to make simple shaders work in both GLSL and GLSL ES
77
- // clang-format off
78
- #ifdef __EMSCRIPTEN__
79
- #define VERT_SHADER_HEADER " #version 100\n #define in attribute\n #define out varying\n precision mediump float;\n "
80
- #define FRAG_SHADER_HEADER " #version 100\n #extension GL_OES_standard_derivatives : require\n #define in varying\n #define fo_FragColor gl_FragColor\n precision mediump float;\n "
81
- #else
82
- #define VERT_SHADER_HEADER " #version 330 core\n "
83
- #define FRAG_SHADER_HEADER " #version 330 core\n out vec4 fo_FragColor;\n "
84
- #endif
85
- // clang-format on
86
-
87
83
Shader::Shader (const std::string &name, const std::string &vs_filename, const std::string &fs_filename,
88
84
BlendMode blend_mode) :
89
85
m_name(name),
@@ -102,8 +98,8 @@ Shader::Shader(const std::string &name, const std::string &vs_filename, const st
102
98
auto vs = load_shader_file (vs_filename);
103
99
auto fs = load_shader_file (fs_filename);
104
100
105
- vertex_shader = string (VERT_SHADER_HEADER) + string ( (char *)vs.data , vs.dataSize );
106
- fragment_shader = string (FRAG_SHADER_HEADER) + string ( (char *)fs.data , fs.dataSize );
101
+ vertex_shader = string ((char *)vs.data , vs.dataSize );
102
+ fragment_shader = string ((char *)fs.data , fs.dataSize );
107
103
108
104
HelloImGui::FreeAssetFileData (&vs);
109
105
HelloImGui::FreeAssetFileData (&fs);
@@ -278,7 +274,8 @@ Shader::Shader(const std::string &name, const std::string &vs_filename, const st
278
274
GLenum type = 0 ;
279
275
GLint size = 0 ;
280
276
CHK (glGetActiveAttrib (m_shader_handle, i, sizeof (attr_name), nullptr , &size, &type, attr_name));
281
- GLint index = glGetAttribLocation (m_shader_handle, attr_name);
277
+ GLint index ;
278
+ CHK (index = glGetAttribLocation (m_shader_handle, attr_name));
282
279
register_buffer (VertexBuffer, attr_name, index , type);
283
280
}
284
281
@@ -288,7 +285,8 @@ Shader::Shader(const std::string &name, const std::string &vs_filename, const st
288
285
GLenum type = 0 ;
289
286
GLint size = 0 ;
290
287
CHK (glGetActiveUniform (m_shader_handle, i, sizeof (uniform_name), nullptr , &size, &type, uniform_name));
291
- GLint index = glGetUniformLocation (m_shader_handle, uniform_name);
288
+ GLint index ;
289
+ CHK (index = glGetUniformLocation (m_shader_handle, uniform_name));
292
290
register_buffer (UniformBuffer, uniform_name, index , type);
293
291
}
294
292
0 commit comments