Reading from PBO fails

classic Classic list List threaded Threaded
8 messages Options
adi
Reply | Threaded
Open this post in threaded view
|

Reading from PBO fails

adi
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?  

Reply | Threaded
Open this post in threaded view
|

Re: Reading from PBO fails

elect
Have you tried glReadPixels on the image you want to read from first (no PBO)?

Just to make sure there is what you expect to be..
adi
Reply | Threaded
Open this post in threaded view
|

Re: Reading from PBO fails

adi
YES, with framebuffers, without PBO, it works correct, e.g.

gl.glBindFramebuffer(GL4.GL_FRAMEBUFFER, framebufId[0]);
gl.glFramebufferTexture2D( GL4.GL_DRAW_FRAMEBUFFER, GL4.GL_COLOR_ATTACHMENT0, GL4.GL_TEXTURE_2D, texId[0], 0);
gl.glReadPixels( ........);
gl.glBindFramebuffer(GL4.GL_FRAMEBUFFER, 0);

The other approach with opengl 4.5 should be also work, or are PBO's deprecated from version 4.5?
Reply | Threaded
Open this post in threaded view
|

Re: Reading from PBO fails

elect
Good, then the error must be here, but it looks fine to me..

Do you have gl debug output on? Any error/warning?


As far as I know, they are not deprecated
adi
Reply | Threaded
Open this post in threaded view
|

Re: Reading from PBO fails

adi
Thanks.
Its not a big problem. For that, i use then framebuffers for reading
such parts from GPU.
Time is here not a factor.  
Reply | Threaded
Open this post in threaded view
|

Re: Reading from PBO fails

elect
adi wrote
Thanks.
Its not a big problem. For that, i use then framebuffers for reading
such parts from GPU.
Time is here not a factor.
Ok, but it would be interesting anyway to find out what was the problem

So I assume you didn't get any gl error/warning..
adi
Reply | Threaded
Open this post in threaded view
|

Re: Reading from PBO fails

adi
Yes you are right, i got no errors
Reply | Threaded
Open this post in threaded view
|

Re: Reading from PBO fails

elect
I might know what is it..

Since it's asynchronous, at the time you copy the data back, it's still empty because it hasn't been executed yet.

Try using Fence/Sync