Get context /Id of QOpenGLBuffer, data wont render - debuging help.
-
Hey
I'm trying to debug a rather "complex" app. From the moment of creation of node to its render, I tried to follow context and debut it at every step. But so far my attempts appear to fail.
The issue I have is that when I generate node, I create shader for it as well as vertex/indices buffer objects. The problem I however have is that when I want to render it and bind the buffers/programs I get a crash on render call.. Its doing my head for past 2 days. Is there a way to find out in what context was my buffer initially created or anything like that? I'm a bit lost.
Here is part of my init function
mVertexBuffer.create(); mVertexBuffer.setUsagePattern(QOpenGLBuffer::StaticDraw); mVertexBuffer.bind(); mVertexBuffer.allocate(vertices, 4 * sizeof(VertexData)); mIndicesBuffer.create(); mIndicesBuffer.setUsagePattern(QOpenGLBuffer::StaticDraw); mIndicesBuffer.bind(); mIndicesBuffer.allocate(indices, 5 * sizeof(GLushort)); mVertexBuffer.release(); mIndicesBuffer.release();
and during draw I call this:
mVertexBuffer.bind(); mIndicesBuffer.bind(); mProgram.bind(); mProgram.enableAttributeArray(mVertexLocationId); mProgram.setAttributeBuffer(mVertexLocationId, GL_FLOAT, offset, 3, sizeof(VertexData)); offset += sizeof(QVector3D); mProgram.enableAttributeArray(mTexcoordLocationId); mProgram.setAttributeBuffer(mTexcoordLocationId, GL_FLOAT, offset, 2, sizeof(VertexData)); mProgram.setUniformValue(mColorId, QVector4D(0.2,0.5,0.1,0.5)); QMatrix4x4 trans; trans.translate(0.5, 0.5, 0.5); mProgram.setUniformValue(mMatrixLocationId, trans); glDrawElements(GL_TRIANGLE_STRIP, 5, GL_UNSIGNED_SHORT, 0);
and glDrawElements pretty much either crash or renders nothing. If I, however, create the buffers again instead of binding old ones above then everything renders as needed. Its as if the bufferes were made in different context or something.
btw do I need VAO ? - maybe I need to make VAO and then Buffer objects hmmm I'm lost.
TIA