0

I'm trying to understand uniform samplers and textures in GLSL. Right now, I understand basic uniforms, in that if I have

uniform float someFloat;

in my shader, I would write (pseudocode) such as

someFloatLoc = glGetUniformLocation(program, "someFloat")
glUniform1f(someFloatLoc, 3.14159)

to set the value of the uniform.

However, if I instead have

uniform shader1d t1;
uniform shader2d t2;

in my shader, what is the corresponding OpenGL function to set the texture? I would expect to find something like glUniformshader2d(uniform_loc, texture) wherein texture is an array specifying the texture, but so far my research leads me to a large number of functions, like glActiveTexture, glGenTextures, glBindTextures, glTexImage2d, and constants like GL_TEXTURE1. But all I'm trying to do is assign an array specifying the texture to a specific shader uniform samplerXd foo so I then can compute the output color based on fetchTexel(foo, texture_coord).

My question can be summarized as follows:

How can I mimic the functionality of glUniform1f for a uniform float in a GLSL shader, but for a uniform sampler instead?

Math Rules
  • 21
  • 7
  • 1
    "*wherein `texture` is an array specifying the texture*" Why would it be an array? – Nicol Bolas Jul 16 '22 at 23:53
  • @Nicol Bolas - the goal is to use the texture and the texelFetch method is to be able to quickly pass a large 2D array to the shader, which is then used to computer the color of a fragment. I have read there is a size limit on arrays of uniforms so basically I am trying to use the texture as a "unlimited" size array of uniforms. – Math Rules Jul 17 '22 at 00:25
  • 1
    My point was about your use of the term "an array specifying the texture". That suggests that the variable named `texture` is an array of some kind, rather than the GLuint name of a texture. It's still doesn't work; you don't pass textures directly to shaders. But what you're trying to pass isn't an array variable. – Nicol Bolas Jul 17 '22 at 00:39
  • @NicolBolas - "you don't pass textures directly to shaders" So where does a shader get a texture if it isn't passed to it? Apparently I'm misunderstanding something here. I thought uniforms were variables passed to shaders? – Math Rules Jul 17 '22 at 00:42
  • 1
    see [Texturing a cube with different images using OpenGL](https://stackoverflow.com/a/65276638/2521214) ... sampler is just single integer representing which texture unit to use ... so you should use `glUniform1i` – Spektre Jul 17 '22 at 05:47
  • some more info about purpose of code, could be much helpful. – Hihikomori Jul 17 '22 at 09:22

0 Answers0