Jump to content
Sign in to follow this  
  • entries
    2
  • comments
    6
  • views
    2503

Really weird bug: Emscripten / OpenGL shader related

Sign in to follow this  
delagames

849 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 [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 smile.png

Happy coding !

-Fakhir
Sign in to follow this  


1 Comment


Recommended Comments

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!