admin管理员组

文章数量:1355592

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?

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?

Share Improve this question edited Mar 31 at 11:38 Maaa aango asked Mar 31 at 10:39 Maaa aangoMaaa aango 213 bronze badges New contributor Maaa aango is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct. 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 – Brett Hale 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. – aled 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. – Maaa aango Commented Mar 31 at 11:50
Add a comment  | 

1 Answer 1

Reset to default 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?

本文标签: javaHow to get data stored in VBOStack Overflow