glMapBuffer

Started by theplayer, May 07, 2009, 15:47:18

Previous topic - Next topic

theplayer

hi @ all

i want to use glMapBuffer to update VBOs dynamicly. i want to use it for my map editor. the map contains of quads. each quad is rendererd as vbo.

i use these methods to map and unmap the buffer
        public static int READ_ONLY = ARBVertexBufferObject.GL_READ_ONLY_ARB;
	public static int WRITE_ONLY = ARBVertexBufferObject.GL_WRITE_ONLY_ARB;
	public static int READ_WRITE = ARBVertexBufferObject.GL_READ_WRITE_ARB;

	public static void mapBuffer(int id, int status, ByteBuffer oldBuffer) {
		ARBVertexBufferObject.glMapBufferARB(id, status, oldBuffer);
	}

        public static void unmapBuffer(int id) {
               ARBVertexBufferObject.glUnmapBufferARB(id);
        }


and this code to map a vbo to the bytebuffer.

        int size = 3 * getVBOSize() * getVBOSize();
        ByteBuffer vertices = BufferUtils.createByteBuffer(size);
        vertices.clear();
        VBO.mapBuffer(selectedVBO, VBO.READ_WRITE, vertices);
        vertices.rewind();
        VBO.unmapBuffer(selectedVBO);


if i use it, i get the error
Exception in thread "main" org.lwjgl.opengl.OpenGLException: Invalid enum (1280)

i thought in the vbo are float values from my vertices and no byte values. how can i map a float buffer or is it possible to calculate from byte to float or should i use byte values and why comes the error?
many questions and my bad english i hope you understand my problem and could help me

thanks for your help

theplayer

theplayer

hi,

nobody here who could help me? i only want to update vbos dynamicaly.

greetings theplayer

Ciardhubh

Quote from: theplayer on May 07, 2009, 15:47:18
i thought in the vbo are float values from my vertices and no byte values. how can i map a float buffer or is it possible to calculate from byte to float or should i use byte values and why comes the error?

I haven't done anything with Vertex Buffer Objects yet so I have no definitive answer. However you can add a call to glGetError() after every gl... call to find out where it originates from. LWJGL only checks for GL errors when you call Display.update(), so it could have been any call that caused the error. Alternatively you could comment out all calls and try each one seperately.

As for the byte buffer, you can put floats into a bytebuffer by calling .putFloat(...) on the byte buffer instance. This takes a float and stores it as 4 bytes. Keep in mind that one value now occupies 4 indices. Depending on how and where you use the buffer, you may have to specify a bigger stride. This works with other data types too, e.g. putInt(...)

Also I think you can remove the .clear and .rewind calls to your buffer in your example.

VeAr