RE: glUniform and multiple textures
Stephan Rose <[email protected]> Sun, 14 Sep 2008 12:35:24 -0800
| Newsgroups | gmane.games.devel.opengl |
|---|---|
| Organization | Fat City Network Services, San Diego, California |
| Message-ID | <[email protected]> |
On Sun, 2008-09-14 at 11:25 -0800, Malcolm Bechard wrote: > It expects the texture unit the texture was bound to, so you were right in > the first case. > > Not sure what the issue is. Found it thanks to your answer. The issue turned out to be completely outside of my render loop which is why I didn't find it. What happened was when loading my color map texture I was accidentally passing my texture format variable containing GL_COMPRESSED_RGBA_S3TC_DXT1_EXT to glBindTexture instead of passing the type variable containing GL_TEXTURE_2D. Amazingly enough, OpenGL still created the texture, but how this managed to get the texture units mixed up like that I have no idea. Fixed that and things work as they are supposed to! Thanks, Stephan > > -----Original Message----- > Stephan Rose > Sent: Sunday, September 14, 2008 2:45 PM > To: Multiple recipients of list OPENGL-GAMEDEV-L > > Can someone explain what precisely glUniform expects as a value when > using it to assign textures? > > I have a shader that makes use of two textures. One is a cubemap used as > a heightmap and the other is a color map (2D Texture) to look up values > based on the height in the cubemap. > > The heightmap is in texture unit 0, the colormap is in texture unit 1. > > I've spent the whole morning trying to get this to work and it just > wouldn't which was really strange as in a previous test application I > got it to work just fine. Just when I took all the spaghetti code and > made a real engine out of it, things stopped working. Go figure... > > Now in my old code, I had this: > > glUniform1i(glGetUniformLocation(programId, "heightMap"), 0); > glUniform1i(glGetUniformLocation(programId, "colorMap"), 1); > > And I used the same in my new code and it didn't work. It worked fine in > my old code.... > > So then I figure, let me look at the texture ID numbers that OpenGL is > giving my two textures, they turn out to be 1 and 2. > > So I change the code to this: > > glUniform1i(glGetUniformLocation(programId, "heightMap"), 1); > glUniform1i(glGetUniformLocation(programId, "colorMap"), 2); > > It works...flawlessly. > > And just for reference, in my shader the variables are defined as: > > uniform samplerCube heightMap; > uniform sampler2D colorMap; > > So what does glUniform expect here? The Texture unit or the texture ID? > > And if it does expect the texture ID, why did it work in my old code > with a Texture ID of 0? And if it expects the texture unit, why is it > working in my new code with 1 and 2 even though the textures are in 0 > and 1? > > I don't like it when something works and I don't understand why it > works. That's just begging for an invitation to come back to haunt me > later and the OpenGL documentation for glUniform is very vague on this > as is trying to find any information about this on Google. > > If someone could clear this up for me I would really appreciate it. > > Thanks, > > Stephan > > > ----- > FAQ and OpenGL Resources at: > http://www.geocities.com/SiliconValley/Hills/9956/OpenGL > > -- > Author: Stephan Rose > INET: [email protected] > > Fat City Hosting, San Diego, California -- http://www.fatcity.com > --------------------------------------------------------------------- > To REMOVE yourself from this mailing list, send an E-Mail message > to: [email protected] (note EXACT spelling of 'ListGuru') and in > the message BODY, include a line containing: UNSUB OPENGL-GAMEDEV-L > (or the name of mailing list you want to be removed from). You may > also send the HELP command for other information (like subscribing) > > ----- > FAQ and OpenGL Resources at: > http://www.geocities.com/SiliconValley/Hills/9956/OpenGL > ----- FAQ and OpenGL Resources at: http://www.geocities.com/SiliconValley/Hills/9956/OpenGL -- Author: Stephan Rose INET: [email protected] Fat City Hosting, San Diego, California -- http://www.fatcity.com --------------------------------------------------------------------- To REMOVE yourself from this mailing list, send an E-Mail message to: [email protected] (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB OPENGL-GAMEDEV-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).