glGetUniformLocation unpredictable behavior

sanjeev mk

I've defined a struct in my fragment shader, as below:

struct light_source{
    vec4 Ld, location;
    int type;
    float radii, specular_exponent;
};  

And I'm using this uniform to access the struct members:
uniform light_source light_sources[5];

Now, from my C++ code, I'm getting the uniform locations like this:

Ld = glGetUniformLocation(Globals::ProgramId, "light_sources[0].Ld");
Ls = glGetUniformLocation(Globals::ProgramId, "light_sources[0].Ls");
location = glGetUniformLocation(Globals::ProgramId, "light_sources[0].location");
type = glGetUniformLocation(Globals::ProgramId, "light_sources[0].type");
radii = glGetUniformLocation(Globals::ProgramId, "light_sources[0].radii");
specular_exponent = glGetUniformLocation(Globals::ProgramId, "light_sources[0].specular_exponent");

When I print the above values, I find that the values are -1,1,2,-1,3,4 . So, I couldn't get locations for Ld and type . Similarly, if I add a new variable to the shader now , some times I get the location, and sometimes I get -1 .

I don't get the problem here. All the variable definitions are correct and there are no typos. Can this behavior be remedied?

ratchet freak

When a uniform/attribute is not being used or has no effect on the output then the compiler/linker is free to remove it entirely which results in the getUniformLocation and glGetAttributeLocation returning invalid values.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Android GridView unpredictable behavior

From Dev

Multithreading "unpredictable" behavior

From Dev

Multithreading "unpredictable" behavior

From Dev

Simple java recursion, unpredictable program behavior

From Dev

Sending a SIGCONT fails silently with unpredictable behavior - linux

From Dev

Unpredictable behavior for strcpy(m+1,m)

From Dev

MPI + OpenMP segmentation fault and unpredictable behavior

From Dev

iText 7: Seemingly unpredictable behavior of table

From Dev

Unpredictable behavior when accessing View from another thread

From Dev

Creating and modifying an empty Pandas DataFrame results in unpredictable behavior

From Dev

Unpredictable FileWriter

From Dev

openGl glGetUniformLocation returns -1

From Dev

glsl vertex shader glGetUniformLocation fails

From Dev

Unpredictable query performance in Postgresql

From Dev

Unpredictable file order in gulp

From Dev

Unpredictable output of recursion of main()

From Dev

Unpredictable poisson noise

From Dev

DbContext SaveChanges unpredictable

From Dev

DIG Unpredictable TTL in DNS

From Dev

Unpredictable file order in gulp

From Dev

Grails/Hibernate Cache unpredictable

From Dev

StopIteration unpredictable bug

From Dev

Explanation of unpredictable behaviour of tee

From Dev

Why Binding works unpredictable?

From Dev

Unpredictable SceneKit behaviour?

From Dev

glGetActiveUniform reports uniform exists, but glGetUniformLocation returns -1

From Dev

Which is faster: calling glGetUniformLocation or using std::map?

From Dev

glGetUniformLocation returns -1 for USED variable, Hell with optimization

From Dev

c++ DirectX 11 glGetUniformLocation equivalent

Related Related

HotTag

Archive