View Full Version : bound textures?
04-26-2004, 11:24 PM
ive just started glsl in my engine, and looking att he glsl specs, and see some great stuff automatically bound such as light info, matrices, and the like, but i see nothing like this for textures?
did i just miss it is there a reason they have not done this? because this means i need to parse my shader, and search for some "sampler*" keyword and do it myself....
04-27-2004, 02:09 AM
Sampler are passed to GLSL via uniforms. You have to do:
glActiveTexture(GL_TEXTURE0 + my_tex_unit);
glUniform1i(glGetUniformLocation("My2DSampler"), my_tex_unit);Where you have defined a 2D sampler in a shader:
uniform sampler2D My2DSampler;EDIT:
Right now there's no possibility to get all samplers out of a program object by calling glActiveUniform because samplers are threated as ints and so you can't say if an uniform is a sampler or an int. But there should be a GLSL specification update in the next time where this problem is solved.
04-27-2004, 03:00 AM
hrmm thinkg something like gl_Position would have been specified
or like gl_LightSourceParameters
i would expect something like gl_Texture0
any idea why they have left this out? :mad:
04-27-2004, 04:31 AM
Don't know but I think this is a good way of binding textures. In your fragment shader you can simple write:
uniform sampler2D My2DSampler;
varying vec2 TexCoord;
gl_FragColor = texture2D(My2DSampler, TexCoord);
}Without bordering at which this texture unit the sampler is bound.
Then in you app you can choose where to bind your texture. If your texture has to be bound at a specific texture unit then simple pass that texture unit using glUniform1i to tell the shader where to sample.
04-27-2004, 07:48 AM
indeed, this method does seem better as it decouples the texture unit used and the shader instead of forcing you to always use a certain texture unit for a certain effect (and as the number of texture units increase this will help with resource wastage)
04-27-2004, 05:26 PM
um both would be good :)
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.