2
votes

I am trying to figure out what determines the buffer object that a uniform samplerBuffer points to.

Let us say we have uniform samplerBuffer aBuffer and its value is 0; what does aBuffer point to?

1
Texture Image Unit 0; I answered a similar question recently, I will point you there. But basically it references the texture bound to that image unit.Andon M. Coleman
@Andon In other words it points to GL_TEXTURE0?Matt Munson
Yes, a samplerBuffer is no different from any other kind of sampler. Really the only unique thing here is the fact that you allocated the thing bound to GL_TEXTURE0 in this example with glTexBuffer (...) rather than say glTexImage2D (...) (in the case of a sampler2D). Well, that and of course, the fact that you have to use texelFetch (...).Andon M. Coleman
@Andon wait, I didn't know that. What if you did bind something using glTexImage2d()?Matt Munson
Then it would not be a buffer texture. That is what this question is about, right? glTexImage2D (...) is for GL_TEXTURE_2D / sampler2D. glTexBuffer (...) is for GL_TEXTURE_BUFFER / samplerBuffer.Andon M. Coleman

1 Answers

2
votes

If I understand your question correctly, you are asking how aBuffer knows which buffer object to fetch texel memory from?

aBuffer is a sampler (more precisely, a buffer sampler), and it has the value 0 in this example, so it refers to the buffer texture (GL_TEXTURE_BUFFER) that is currently bound to GL_TEXTURE0.

The association between the buffer texture bound to GL_TEXTURE_BUFFER and the backing storage comes from the last parameter in the call to glTexBuffer (...). That last parameter is the name of a buffer object.