Updating VBO data with glMapBuffer

Started by Daslee, December 16, 2013, 13:55:09

Previous topic - Next topic

Daslee

Hello. I found a new way updating vertices data in vbo with glMapBuffer (before this I was re-initializing vbo every frame), but it doesn't works for me. As I mentioned I'm re-initializing vbo every frame so this way everything works fine, if I don't do it so objects stays in same position, but if I add that code with glMapBuffer instead of re-initializing vbo so I can't event see my objects. Here is my code how I'm doing it:

glBindBuffer(GL_ARRAY_BUFFER, verticesHandle);
mappedBuffer = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY, mappedBuffer);
vertices = mappedBuffer.order(ByteOrder.nativeOrder()).asFloatBuffer();
for(int i=0; i<snowflakes.length; i++){
	vertices.put(snowflakes[i].getVertices());
}
vertices.flip();
glUnmapBuffer(GL_ARRAY_BUFFER);


Where is the problem?

Fool Running

You shouldn't have to call ".order(ByteOrder.nativeOrder()).asFloatBuffer()" on the buffer as that should be what was returned. I'm not sure if that is causing your problem, but I would start there.
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

Daslee

I don't think that this is causing my problem. http://www.java-gaming.org/index.php?topic=24272.0 look at Mapped Vertex Buffer Object example, author also changes from ByteBuffer to FloatBuffer.

quew8

What @Fool Running means is that the ".order(ByteOrder.nativeOrder())" is not necessary. That bit makes sure that the order and endianness of the buffer is that of the native system (because that's the one OpenGL will use). Since OpenGL uses that, it's always going to return a buffer with the native byte order. The ".asFloatBuffer()" returns a FloatBuffer representation of the ByteBuffer. I think the problem you have is one or more of two problems:

1) Something's going wrong on the OpenGL end. Make sure you have checked for an OpenGL error with glGetError().

2) The position and or limit of the ByteBuffer is wrong. When you get a FloatBuffer representation with asFloatBuffer(), it's only the same buffer in that it works on the same information. It's position, limit, mark etc. are all independent. That means that when you call flip() on the FloatBuffer, it has no effect on the ByteBuffer. So the position and limit of the ByteBuffer could be causing you problems. I've never managed to come up with an elegant solution to this. I tend to just to iterate through the array and add each float (or int or whatever) using the putFloat() method of ByteBuffer.

Daslee

GLU.gluErrorString(glGetError());


Says this: Invalid operation

And I have no idea where is invalid operation in my code.  ;D

quew8

Check the OpenGL error before and after each OpenGL method in the new code you've written. Then you can look up the method in the docs here: http://www.opengl.org/sdk/docs/man4/. It will tell you which errors that method throws and why.