1

I need to get back a float[] of vertices which is stored in attrList in vbo in vao.
I do:

float[] b = new float[vertexCount];
glBindVertexArray(vaoId);
long pointer;
glEnableVertexAttribArray(0);
pointer = glGetVertexAttribPointer(0,  GL_VERTEX_ATTRIB_ARRAY_POINTER);
glBindBuffer(GL_ARRAY_BUFFER, (int) pointer);
glGetBufferSubData(GL_ARRAY_BUFFER, 0, b);

All data in vaos and vbos is stored correctly, I can draw things perfectly.
The problem here is that variable pointer returns 0.
What am I doing wrong?

3
  • I'd just keep the buffer b[] around - but assuming you don't want to do that, look at: glMapBuffer with: GL_ARRAY_BUFFER, GL_READ_ONLY Commented Mar 31 at 11:01
  • What is the question? How to port the code to C++ or how to resolve the issue in Java? Don't ask two question in one, it is off topic and can get your question to be closed. Commented Mar 31 at 11:30
  • @aled I am asking whether my approach(sequence of actions) correct or not, so all java or c/c++ related answers would be helpful. Commented Mar 31 at 11:50

1 Answer 1

1

No, your code is nonsense.

From the documentation of glGetVertexAttribPointer:

The pointer returned is a byte offset into the data store of the buffer object that was bound to the GL_ARRAY_BUFFER target (see glBindBuffer) when the desired pointer was previously specified.

You should thus pass pointer as the offset parameter of your glGetBufferSubData call. Your code treats it as the name of the VBO that was bound (because you call glBindBuffer); if you want to retrieve that you can ask using glGetVertexAttrib(0, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING). Same goes for the stride, divisor, etc.

But all of this smells like a giant XY problem: you should know the values that were used at setup time, no?

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for clarification! And yes, I potentially can use data from the setup, just thought it would mean I have to store it an extra time for this purpose.
Unless you're very resource constrained or loading lots of huge models, I would say don't bother.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.