Really weird bug: Emscripten / OpenGL shader related
1,570
1
Advertisement
Hi,
This is just a quick short entry.
Today I tried to compile a small but fully working OpenGL ES 2 shader related code in Emscripten. It didn't work. After a LOT of time debugging I found out that if I call [font='courier new']glBindAttributeLocation(...)[/font] BEFORE actually linking the shader programit works perfectly. So the following code works fine:[code=auto:7]....glAttachShader(_programID, _fragmentShaderID);glAttachShader(_programID, _vertexShaderID);glBindAttribLocation(_programID, VERTEX_ARRAY, "a_position");glBindAttribLocation(_programID, COLOR_ARRAY, "a_color");glLinkProgram(_programID);.......
BUT the following code will DID NOT work with emscripten WebGL:[code=auto:7]....glAttachShader(_programID, _fragmentShaderID);glAttachShader(_programID, _vertexShaderID);glLinkProgram(_programID);glBindAttribLocation(_programID, VERTEX_ARRAY, "a_position");glBindAttribLocation(_programID, COLOR_ARRAY, "a_color");.......
So the best way is to get pre bound attribute location using use [font='courier new']glGetAttribLocation(..)[/font] rather than manually binding it:[code=auto:7]....if(!LoadProgramFromFile("Default.vert", "Default.frag")){ printf("Error Error loading program from file...\n"); return false;} _a_positionLoc = glGetAttribLocation(_programID, "a_position"); _a_color = glGetAttribLocation(_programID, "a_color");....
This may save you a LOT of headache
Happy coding !
-Fakhir
This is just a quick short entry.
Today I tried to compile a small but fully working OpenGL ES 2 shader related code in Emscripten. It didn't work. After a LOT of time debugging I found out that if I call [font='courier new']glBindAttributeLocation(...)[/font] BEFORE actually linking the shader programit works perfectly. So the following code works fine:[code=auto:7]....glAttachShader(_programID, _fragmentShaderID);glAttachShader(_programID, _vertexShaderID);glBindAttribLocation(_programID, VERTEX_ARRAY, "a_position");glBindAttribLocation(_programID, COLOR_ARRAY, "a_color");glLinkProgram(_programID);.......
BUT the following code will DID NOT work with emscripten WebGL:[code=auto:7]....glAttachShader(_programID, _fragmentShaderID);glAttachShader(_programID, _vertexShaderID);glLinkProgram(_programID);glBindAttribLocation(_programID, VERTEX_ARRAY, "a_position");glBindAttribLocation(_programID, COLOR_ARRAY, "a_color");.......
So the best way is to get pre bound attribute location using use [font='courier new']glGetAttribLocation(..)[/font] rather than manually binding it:[code=auto:7]....if(!LoadProgramFromFile("Default.vert", "Default.frag")){ printf("Error Error loading program from file...\n"); return false;} _a_positionLoc = glGetAttribLocation(_programID, "a_position"); _a_color = glGetAttribLocation(_programID, "a_color");....
This may save you a LOT of headache
Happy coding !
-Fakhir
Advertisement
Advertisement
Advertisement
Discussion