Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MODERN OPENGL can't change uniform value beetween glDrawArrays calls

EDIT: I just managed to fix the issue by reinstalling PyOpenGL with pip. The same program now works as expected. Thanks for your efforts.

The entire question was rewritten and clarificated.

The issue does not lie in the (although weird) Texture creation and binding approaches, as explained in the comments.

My actual problem is the fact that uniform variables in the shaders are not updating their values when changed (yes, changed from outside the shader) between calls to glDrawArrays(). I verified that by using different types of uniforms, different values and checking their values by rendering to a texture.

It seems like the values of the uniforms are locked as soon as glDrawArrays() is called. After that, I can only change them again when the color Buffer is cleared.

I am willing to give a bounty for any working solution. Posting any source code is not helpfull in my opinion, as the problem does NOT seem to lie in the code.

Any suggestions are apprechiated.

like image 767
xXliolauXx Avatar asked Oct 19 '22 16:10

xXliolauXx


1 Answers

You can update uniforms between draw calls, that's how they are meant to be used.

Looking at the pasted code, and as pointed out in the comments, lines 167..169 should work by chance for small texIds, but you should really change

glUniform1i(textureUnif, model.texId)
glActiveTexture(GL_TEXTURE0+model.texId)
glBindTexture(GL_TEXTURE_2D, model.texId)

to

glUniform1i(textureUnif, 0)
glActiveTexture(GL_TEXTURE0)
glBindTexture(GL_TEXTURE_2D, model.texId)

though since all you use is GL_TEXTURE0, you only really need the glBindTexture() call on each loop iteration. The texture uniform should contain the texture unit, the shader has no concept of texture id in this case.

Of course, this being OpenGL, errors are often hard to find. What are you actually trying to draw? Screenshots would be helpful.

It might well be that something else in the OpenGL state results in the uniform update not showing up on the screen, for example depth testing is one common culprit.

like image 52
dognotdog Avatar answered Nov 02 '22 13:11

dognotdog