LWJGL 3 - shader uniforms changing during rendering

Started by yan.p, April 09, 2015, 06:22:59

Previous topic - Next topic

yan.p

Hi all,

I'm struggling to find the cause for an issue where my uniforms seem to be changing value in the middle of a glDrawArrays call. The attached program should display alternating blue/green columns of triangles, where each triangle's color is passed to the shader as a uniform. Apologies for the messy code, but it's a (minimal) cut-down example from a larger app. I'm using the latest stable LWJGL 3 release.

It all works fine if I loop through my VAOs and render them individually. However, if I create a (temporary) VAO & populate a VBO during rendering, the colors become random - even down to individual fragments within a triangle (see screenshots). I'm a relative newbie to OpenGL, so would appreciate any advice on what I'm doing wrong.

Thanks.

quew8

Quote from: yan.p on April 09, 2015, 06:22:59
...
It all works fine if I loop through my VAOs and render them individually. However, if I create a (temporary) VAO & populate a VBO during rendering...

Thanks.

Not sure I understand what you mean by this. And could you post the fragment shader and just the code where you set this uniform.

yan.p

Sure. Here's the fragment shader:

#version 330 core
 
uniform vec4 color;
 
layout(location = 0) out vec4 fragColor;

void main()
{
     fragColor = color;
};


Here's the bit of code which sets the uniform:

int colorId = glGetUniformLocation(shader.getID(), "color");
glUniform4f(colorId, color[0], color[1], color[2], color[3]);


If you need more details, all the code (including shaders) is attached as self-contained runnable example in my first post.

QuoteNot sure I understand what you mean by this.

Have a look at Test.render() in the attached code. The following works:

for each triangle:
    bind shader
    set uniforms
    bind vao & enable attrib array
    glDrawArrays
    unbind vao & disable attrib array
    unbind shader

However, this doesn't:

for each triangle:
    (exact same as above)
    create a new array & buffer
    set buffer data --> the call to glBufferData is what seems to cause the problem.
    delete buffer & array

quew8

So I was so vexed by why this might be happening that I compiled and ran your test class myself. When I did it, I got perfect results whether the block in question is run or not. So I'm going to go ahead and put this down to a driver bug. (I tested using my integrated "Intel HD Graphics" card).

So make sure you're using the latest drivers. If you are, you can try installing an older driver. Search online for bugs in your specific card/driver. Frankly, there are others on this forum with much more experience than me in this sort of thing. Hopefully one of them can help you out if you can't find any info. So you should probably post your graphics card & driver version for them.

yan.p

Yep, I installed the latest driver and it fixed the problem.
Thanks for that, it was driving me crazy!

quew8

Happy to help. Just be pleased that updating solved the problem, and let this be a lesson to you. Always use the latest software.