Jump to content

  • Log In with Google      Sign In   
  • Create Account






Really weird bug: Emscripten / OpenGL shader related

Posted by delagames, 12 July 2014 · 247 views

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 glBindAttributeLocation(...) BEFORE actually linking the shader programit works perfectly. So the following code works fine:
....
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:
....
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 glGetAttribLocation(..) rather than manually binding it:
....
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 Posted Image

Happy coding !

-Fakhir




Just a heads up, this isn't a bug - it's intentional behaviour. Calling glBindAttribLocation doesn't have any effect until you call glLinkProgram (when the driver can link up everything in the right place :)) See here: https://www.khronos.org/opengles/sdk/docs/man/xhtml/glBindAttribLocation.xml

August 2014 »

S M T W T F S
     12
3456789
10111213141516
17181920 21 2223
24252627282930
31      
PARTNERS