PDA

View Full Version : GetUniformLocation returning -1



EricHosick
11-13-2011, 03:39 AM
I have the following uniform block:



uniform BlobSettings {
vec4 InnerColor;
vec4 OuterColor;
float RadiusInner;
float RadiusOuter;
};

I can query how many of these I have and their name and get the correct answer:



for(int i=0; i < activeUniformsCount; i ++ {
GetActiveUniform(shaderProgramID, i, maxLength, out written, out size, out type, name );
int location = Program.GetUniformLocation(shaderProgramID, name);
}


I get the value in name of:
BlobSettings.InnerColor
BlobSettings.OuterColor
BlobSettings.RadiusInner
BlobSettings.RadiusOuter

I even get the right type out.

However, the value of location is always -1.

I am also asking because I get similar results for GetUniformIndices (all indicies are -1).

I have to be doing something wrong! What is it?

Note that the code is out of the book Getting Started With GLSL 4.0 (pg 38-40).

EricHosick
11-13-2011, 04:32 AM
Reply to myself:

Although the GetUniformLocation is still returning -1, I had mentioned that GetUniformIndices was also returning -1 as follows:


I am also asking because I get similar results for GetUniformIndices (all indicies are -1).

The example in the book is as follows:



const GLchar *names[] = { "InnerColor", "OuterColor", "RadiusInner", "RadiusOuter" };
GLuint indices[4];
glGetUniformIndices(programHandle, 4, names, indices);


when I change names to this:



const GLchar *names[] = { "BlobSettings.InnerColor", "BlobSettings.OuterColor", "BlobSettings.RadiusInner", "BlobSettings.RadiusOuter" };


It works.