PDA

View Full Version : Regarding texture buffer object



mobeen
07-09-2011, 01:34 AM
Hi all,
I have a texture buffer object containing integer values so I refer to it in the shader as


uniform isamplerBuffer tex_counts;


now to obtain a value from it, i call


texelFetchBuffer(tex_counts, gl_VertexID);

but this returns an ivec4. I am only interested in a single value so should i do this?


int count = texelFetchBuffer(tex_counts, gl_VertexID).x;

Or is there any other function to obtain a single int value from the texture buffer?

Another question is can I attach a texture buffer object to a vbo without enabling the vertex attribute? I want to store a buffer containing counts. Can I store the data into a vbo and for convenience of access attach it to a texture buffer object but not attach a vertex attribute to the vbo?

Alfonse Reinheart
07-09-2011, 03:53 AM
Or is there any other function to obtain a single int value from the texture buffer?

You mean, besides the GLSL 1.30 function "texelFetch" that can access texels from just about anything without having to have the "Buffer" suffix? No. But the 1.30 function also returns a gvec4 (where g is either nothing, i, or u, as appropriate to the sampler).

Just pick the first component as you currently are. There's nothing wrong with that.


Another question is can I attach a texture buffer object to a vbo without enabling the vertex attribute? I want to store a buffer containing counts. Can I store the data into a vbo and for convenience of access attach it to a texture buffer object but not attach a vertex attribute to the vbo?

You don't attach vertex attributes to buffer objects. You use them for sources of vertex attributes. So I'm not sure what you're asking.

Can you use a buffer object as source for both vertex data and buffer textures? Yes. It's just a buffer object; you can use them for anything.

mobeen
07-09-2011, 09:43 AM
You use them for sources of vertex attributes.

OK so can i use the buffer object only as a buffer without associating any per vertex attribute?
Let me illustrate what I mean by an example. Usually when we add the vertex data, we bind the buffer object, then we issue a glBufferData call, following which we enable the vertex attribute and call glVertexAttribPointer. Now currently I only want a buffer containing counts so can i simply call glBindBuffer(...) and then glBufferData without giving the call to glEnableVertexAttribute(..) and glVertexAttribPointer? And then later attach the buffer object to a texture buffer to enable easy access in the vertex shader.

Alfonse Reinheart
07-09-2011, 01:36 PM
OK so can i use the buffer object only as a buffer without associating any per vertex attribute?

Yes. Buffer objects (http://www.opengl.org/wiki/Buffer_Object) are just linear arrays of memory allocated by OpenGL.

mobeen
07-09-2011, 11:09 PM
Thanks for the response Alfonse.