Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


d0Sm4o20

Member Since 13 Feb 2011
Offline Last Active Apr 22 2012 07:23 PM

Posts I've Made

In Topic: [SOLVED] GLSL subroutine not getting used

09 April 2012 - 01:38 AM

After a lot of pain, I figured out that I was indirectly calling glUseProgram() twice with my framework. The first time, to set the subroutine, the second time, in the draw() method of my shader program object. Apparently subroutine selection *do not* persist in shader program state, so it was being reset on the second call.

Hopefully this saves someone some time! :)

In Topic: Bizarre GLSL link error

04 December 2011 - 04:55 PM

So the last one just doesnt link still? Or does it give you an invalid uniform location?


Well, it never actually gets to the point where I get the uniform location. The code fails on linking the compiled shaders, so I can't even assign a uniform yet.

That's a weird limitation if I can only use a uniform for loops that don't modify an "out" variable, but I'll have to accept it I guess if it's true.

In Topic: Bizarre GLSL link error

04 December 2011 - 03:43 AM

After a lot of poking at the shader code (and updating my drivers), I've come to the conclusion that I can't do the following things together:

I can't have a loop based on a uniform expression AND have that loop alter an "out" array.

For example, this works:


#version 420

layout(location = 0) in vec4 position;
out int derp[10];

uniform int num_lights;

void main(void) {
	for (int i=0; i<10; i++) {
		derp[i] = i;
	}
	
	gl_Position = position;
}


And this works:
#version 420

layout(location = 0) in vec4 position;
out int derp[10];

uniform int num_lights;

void main(void) {
	int j = 0;
	for (int i=0; i<num_lights; i++) {
		j += i;
	}
	
	gl_Position = position;
}

But this doesn't:

#version 420

layout(location = 0) in vec4 position;
out int derp[10];

uniform int num_lights;

void main(void) {
	for (int i=0; i<num_lights; i++) {
		derp[i] = i;
	}
	
	gl_Position = position;
}




Really bizarre behavior.

In Topic: Bizarre GLSL link error

04 December 2011 - 02:17 AM

Yeah, I think I see what you're saying about unrolling the loops. I googled "glsl uniform loop" and it seems that there have been a lot of people with issues of using a uniform in the expression part of a loop. This could be my problem. If I set the expression to a constant value, either through a #define, or with some fixed value in the code, it works fine.

I double-checked my glGetUniformLocation and it's not returning -1, so I think that's fine. It must be the uniform in the loop creating undefined behavior. Might be a bug in the driver. I'm going to upgrade my driver right now actually and see if that solves it.

In Topic: Bizarre GLSL link error

03 December 2011 - 10:43 PM

What may be going on is that I have had (and others) where shaders do not work if you dont explicitly use a uniform. Sometimes shaders unroll your loops and since your loop never uses the index "i", it again is probably optimizing it. So STOP IT!


I probably should've clarified why I wasn't using "i" to index vlight. I was using "i" first, which is where the error first surfaced. So instead, I created "j" just to see if I could get the same bad behavior with a variable that wasn't being compared to num_lights, which it did.

I'll keep poking at it more. I'm clearly messing around with some very undefined behavior, so this is turning out to not be easy.

PARTNERS