Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have been writing GLSL shaders for over a year but this is the first time I have run into this problem. I am on the iOS platform - if that matters.

In a vertex shader I have this:

uniform mediump mat4 projectionViewModelMatrix;

In a fragment shader I have been using for months I have the following uniforms:

uniform int channels;
uniform sampler2D hero;

Nothing to write home about. I added three additional uniforms to the fragment shader:

uniform int heroChannels;
uniform int heroWidth;
uniform int heroHeight;

Using

glGetUniformLocation

I tried to grab the location of all my uniforms. This is when my own personal hell began. This is the result:

uniform heroChannels location -1
uniform channels location 4
uniform hero location 5
uniform heroHeight location -1
uniform projectionViewModelMatrix location 0
uniform heroWidth location -1

Huh? Why are the recently added uniforms not given a valid location by the GL Gods?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

Couple things come to mind.

First, it's possible each of your int uniforms actually takes a whole vector in uniform space, and thus you may be running out of space - you can try to combine them into vectors to see if it helps.

Second, it's possible that the shader compiler happily discards the uniforms in case they're not actually in use. If this is the case, then they naturally won't get a location.

share|improve this answer
    
Jari, is there any way to force the compiler not to discard unused variables? –  dugla Jan 18 '11 at 16:39
    
@dugla: The glUniform function family specifically does not error on location -1 to make situations like this work, as unused variables are fairly common with stitched shaders. Why worry about it? –  user744 Jan 18 '11 at 16:46
    
Jari you nailed it. The newly added uniforms were indeed unused. Assigning them to int dev_null forced them to be recognized. Good catcht. Sigh, GL is such a pain. Cheers. –  dugla Jan 18 '11 at 16:47
    
@Joe_Wreschnig, I am building a basic shader dictionary for an iOS app I am writing. My thought was to create an dictionary for each shader in my library with the uniforms and attributes as elements in the shader dictionary. Just a way to clean up some of the endless bookkeeping in GL. –  dugla Jan 18 '11 at 16:49
1  
@dugla: But you're doing more bookkeeping than necessary. Just store the glGetUniform returns, pass them back in to set the uniforms later, and you don't need to care if they're -1 or not. –  user744 Jan 18 '11 at 16:52
show 5 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.