|
This post was updated on .
Hello
I'm load up a simple texture in GPU with:
..........
int[] tex_Id = new int[1];
gl.glGenTextures( 1, tex_Id, 0);
gl.glBindTexture( GL4.GL_TEXTURE_2D, tex_Id[0] );
............
gl.glTexImage2D( GL4.GL_TEXTURE_2D, 0, GL4.GL_RGBA, width, height, 0, GL4.GL_RGB, GL4.GL_UNSIGNED_BYTE, datas);
...........
Then i will read it back with:
.......
// creating copy buffer
ByteBuffer datas = ByteBuffer.allocateDirect( width*height*3).order(ByteOrder.nativeOrder());
// Generate a PBO on the GPU using glGenBuffers
int[] pbo_Id = new int[1];
gl.glGenBuffers(1, pbo_Id, 0);
// Bind PBO to pack buffer target
gl.glBindBuffer(GL4.GL_PIXEL_PACK_BUFFER, pbo_Id[0]);
// Allocate buffer space on GPU according to data size using glBufferData
gl.glBufferData(GL4.GL_PIXEL_PACK_BUFFER, datas.capacity(), null, GL4.GL_STREAM_READ);
// Decide what framebuffer to read using glReadBuffer.
gl.glReadBuffer(GL4.GL_COLOR_ATTACHMENT0);
// Use glReadPixels to read pixel data from the targeted framebuffer to the bound
// PBO. This call does not block as it is asynchronous when reading to a PBO as
// opposed to CPU controlled memory
gl.glReadPixels(0, 0, width, height, GL4.GL_RGB, GL4.GL_UNSIGNED_BYTE, 0);
// Map PBO to CPU memory denying GPU access for now. glMapBuffer returns
//a pointer to a place in GPU memory where the PBO resides
ByteBuffer srcBuf = gl.glMapBuffer(GL4.GL_PIXEL_PACK_BUFFER, GL4.GL_READ_ONLY);
// also not working, gl.glMapBufferRange(GL4.GL_PIXEL_PACK_BUFFER, 0, datas.capacity() , GL4.GL_MAP_READ_BIT);
// Copy data from GPU to CPU using pointer from glMapBuffer
datas.put(srcBuf);
// Unmap PBO (glUnmapBuffer) to allow GPU full access of the PBO again
gl.glUnmapBuffer(GL4.GL_PIXEL_PACK_BUFFER);
//Unbind the PBO to allow for normal operation again
gl.glBindBuffer(GL4.GL_PIXEL_PACK_BUFFER, 0);
datas.clear();
Normally there must be the byte color values from the texture that i have created, but all bytes are set to 0.
Can't see an error on my code. Have i overseen something?
|