PDA

View Full Version : Rendering contents of Shader Storage Buffer Object and Invalid Operation Error



ceebee
09-11-2012, 01:48 PM
I'm trying to use the new OpenGL 4.3 compute shader.

I working with a GL_SHADER_STORAGE_BUFFER which is passed to the compute shader and then I am trying to render the computed results.
However I am getting hung up on drawing the contents of the Shader Storage Buffer as ARRAY_BUFFER

In a nutshell here is the buffer

glGenBuffers(1, &posSSbo);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, posSSbo);
glBufferData(GL_SHADER_STORAGE_BUFFER, particles * sizeof(struct pos), NULL, GL_STATIC_DRAW);


// init vertex position buffer
GLint bufMask = GL_MAP_WRITE_BIT|GL_MAP_INVALIDATE_BUFFER_BIT;


struct pos *points = (struct pos *)glMapBufferRange(GL_SHADER_STORAGE_BUFFER, 0, particles * sizeof(struct pos), bufMask);
for (auto i=0;i<particles;i++) {
points[i].x = (0.5f-float(std::rand())/RAND_MAX) * 5.0f + 0.0f;
points[i].y = (0.5f-float(std::rand())/RAND_MAX) * 5.0f + 20.0f;
points[i].z = (0.5f-float(std::rand())/RAND_MAX) * 5.0f + 0.0f;
points[i].w = 1.0f;
}
glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);

.. call compute shader...

.. try to draw ...
glMemoryBarrier(GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT );
glBindBuffer( GL_ARRAY_BUFFER, posSSbo );
glVertexAttribPointer(0,4,GL_FLOAT,GL_FALSE,4*size of(GLfloat),(void *)0 ); <-- Get Invalid Operation Here

I have looked at both Mike Bailey's Sigragph 2012 notes: https://docs.google.com/viewer?url=http%3A%2F%2Feducation.siggraph.org%2Fm edia%2Fconference%2FS2012_Materials%2FComputeShade r_2pp.pdf
and the spec for Shader Storage Buffer object http://www.opengl.org/registry/specs/ARB/shader_storage_buffer_object.txt and they have similar code. In fact the above code is copied from Mike Bailey's notes.

I have seen comments that you need to have a bound ARRAY_BUFFER (which makes sense) to prevent an Invalid Operation but I am clueless as to why I am getting this error.

Any ideas or comments would be really appreciated.

Craig