5

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.

xXliolauXx
  • 1,273
  • 1
  • 11
  • 25
  • 2
    How are you testing for the value? Can you create a [mcve]? – Colonel Thirty Two Jan 31 '16 at 18:38
  • I tested the values multiple ways, including using the passed value as a color or using it inside an if statement. I'll try to filter out all the unnecessary stuff to give an appropriate example. – xXliolauXx Jan 31 '16 at 18:43
  • 3
    Your problem is not in the posted code. There are obvious problems in the linked code, but the relevant code needs to be posted in the question itself. Then again, it would be very similar to something that has been asked here many times. You're confusing the concepts of texture units and texture ids (names). See for example my answer here: http://stackoverflow.com/q/30006525/3530129. Or for a more detailed explanation that covers additional concepts: http://stackoverflow.com/q/30960403/3530129. – Reto Koradi Feb 01 '16 at 00:26
  • @Reto Koradi Thanks for the input, I read the other answers and changed my program accordingly. From what I understand, I should now be able to switch between the textures by just updating the value in the tex uniform, it still draws the same texture for all glDrawArrays calls. Still, any help apprechiated. – xXliolauXx Feb 01 '16 at 19:41
  • @Reto Koradi btw, I still think the issue lies in the fact that I cannot change the value of Uniforms between glDrawArrays() calls. What makes me think so is the fact that the texture IS beeing swtiched (though for all draw calls) when I change the value that is initially passed to the tex uniform. – xXliolauXx Feb 01 '16 at 19:44
  • Unfortunately, the problem almost certainly lies in your code, unless you happen to have a really weird bug on your system. OpenGL is very fickle, and maybe something only remotely related is fouling up the state, so that for whatever reason the uniform update is not performed in the expected manner, maybe wrong program being bound or the uniform location being wrong, etc, which are all very hard to diagnose without the actual code. Even if it's a true bug in your OpenGL drivers, it's very hard to localize without working source code. – dognotdog Feb 02 '16 at 21:57
  • PS: From the way you put it, it seems like something happens in your per-frame setup that is different from the loop you posted earlier. It could be that your per-model drawing code changes something that prevents the uniform update. – dognotdog Feb 02 '16 at 22:03
  • @dognotdog Alright I'll go through it then and filter out all the ogl calls... Bit that will have to wait until this afternoon. Thanks for your efforts. – xXliolauXx Feb 03 '16 at 05:59

1 Answers1

3

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.

dognotdog
  • 681
  • 3
  • 14
  • I'll reward the bounty to your answer, altough it did not exactly solve the problem, it is a good one. Would be a shame to waste the 50 rep ;) – xXliolauXx Feb 09 '16 at 19:42