Hello Guest

LWJGL 3 - shader uniforms changing during rendering

  • 5 Replies
  • 6310 Views
LWJGL 3 - shader uniforms changing during rendering
« on: April 09, 2015, 06:22:59 »
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.

*

Offline quew8

  • *****
  • 569
  • Because Square Eyes Look More Real
Re: LWJGL 3 - shader uniforms changing during rendering
« Reply #1 on: April 10, 2015, 10:17:43 »
...
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.

Re: LWJGL 3 - shader uniforms changing during rendering
« Reply #2 on: April 11, 2015, 00:54:41 »
Sure. Here's the fragment shader:

Code: [Select]
#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:

Code: [Select]
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.

Quote
Not 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

*

Offline quew8

  • *****
  • 569
  • Because Square Eyes Look More Real
Re: LWJGL 3 - shader uniforms changing during rendering
« Reply #3 on: April 11, 2015, 18:29:43 »
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.

Re: LWJGL 3 - shader uniforms changing during rendering
« Reply #4 on: April 12, 2015, 23:22:27 »
Yep, I installed the latest driver and it fixed the problem.
Thanks for that, it was driving me crazy!

*

Offline quew8

  • *****
  • 569
  • Because Square Eyes Look More Real
Re: LWJGL 3 - shader uniforms changing during rendering
« Reply #5 on: April 13, 2015, 00:35:17 »
Happy to help. Just be pleased that updating solved the problem, and let this be a lesson to you. Always use the latest software.