Skip to content Skip to sidebar Skip to footer

Glmapbufferrange Returning All Zeros In Android

I am having trouble reading out from a buffer mapped with glMapBufferRange If I simply put some data in a buffer // Create input VBO and vertex format int bufferLength = 5

Solution 1:

This looks like a byte order problem when you read back the data. The data will be in native byte order, while Java assumes by default that data in buffers is big endian. Since most architectures are little endian these days, that's the opposite of what you need.

To correct for this in a way that will work for both big and little endian architectures, you can do the following:

ByteBufferbyteBuf= (ByteBuffer)mappedBuffer;
byteBuf.order(ByteOrder.nativeOrder());
FloatBufferfloatBuf= byteBuf.asFloatBuffer();

Then when you read from floatBuf, you should get the correct values.

Solution 2:

Big thanks to Reto Koradi, if anyone wants to leave an answer I will mark it as correct.

The casting was incorrect. Needs to be in LITTLE_ENDIAN order:

ByteBuffer transformedBuffer = ((ByteBuffer) mappedBuffer);
transformedBuffer.order(ByteOrder.LITTLE_ENDIAN);

Log.d(TAG, String.format("pre-run input values = %f %f %f %f %f\n", transformedBuffer.getFloat(),
                transformedBuffer.getFloat(), transformedBuffer.getFloat(),
                transformedBuffer.getFloat(), transformedBuffer.getFloat()));

Post a Comment for "Glmapbufferrange Returning All Zeros In Android"