AnsweredAssumed Answered

[compute shader] efficient way to fetch values from buffer object

Question asked by laobrasuca on Aug 13, 2012
Latest reply on Aug 28, 2012 by gsellers



in OpenCL big non fixed size arrays of data are commonly passed as cl_mem objects (unformatted byte buffers within  global memory scope) which are seen in the OpenCL kernel as pointers, like traditional C arrays: typeName* varName Thus, accessing a value from this array is simply done by using the operator []: typeName a = varName[2]. How about GLSL, specially for compute shaders? In my experience with vertex shaders, I pass generic buffers as texture buffers like


glGenBuffers(1, &tex_Buffer);


glBindTexture(GL_TEXTURE_BUFFER, tex_Buffer);


glBindBuffer(GL_TEXTURE_BUFFER, tex_Buffer);.

glBufferData(GL_TEXTURE_BUFFER, data_size_in_bytes, data_array, GL_STATIC_DRAW);

glTexBuffer(GL_TEXTURE_BUFFER, GL_DATA_TYPE, tex_Buffer);


and in the shader program I use uniform (TYPE)samplerBuffer varName and fetch values from array with texelFetch. Is that the best way to do it for generic type non fixed size and random read/write access data buffers?


I heard about buffers, instead of samplerBuffer, but it seems to be intended to other usages, since they are more limited in size and not well designed for random access.