implementing my own JComponent with jogl backbuffer : performance bottleneck ?

Hi,

I needed to perform some offscreen opengl rendering for mixing java2D/Jogl purposes. I finally ended up writing a small test case with a JPanel drawing a BufferedImage (as an offscreen image).
This offscreen image is filled directly by a glReadPixel after a PBuffer display (glreadPixel directly fills the byte array of my BufferedImage for performance)

I then realized that I somehow reinvented the GLJpanel… but less performant obviously !

Although I do not claim to match the GLJpanel, I would like to know where I am loosing performance here
pbuffer.display() --> glReadPixels (directly on BufferedImage’s byte array (wrapped in a ByteBuffer)) --> graphics.DrawImage(offscreenImage)

And it is approximately 40% slower than the GLJpanel

Thanks for any hint .

Could be several causes:

Doing any communication with native code with non-direct buffers requires a data-copy. (ByteBuffer from wrapping a byte[] is non-direct)
The pixel-format of the PBuffer might not be RGB8, forcing a conversation for each pixel.
It could also be too much context-switches, but I don’t have knowledge of your code.

Or anything I didn’t think of… isn’t the code of GLJPanel publicly available? You could check out the diffs.

“… isn’t the code of GLJPanel publicly available”

It is indeed, and I had a look at it before asking this question, but I probably did not dig deep enough to spot any relevant difference.
It seemed to me that major steps were almost the same. For instance, the bytebuffer used to read back pixels from opengl is not direct (in GLJPanel), I do not think that I am switching contexts a lot, might be for the pixel format conversion though…

ANyway, thanks for your input. I’ll also try to actually use the GLJpanel to perform offscreen rendering (without having to display it), it this is feasible

Ok, I found it

It was actually the format of my Buffered image. I was using INT_RGB and switched to 4BYTES_ABGR (with a change in the format within glReadPixels accordingly) and I get the same level of performance as GLJpanel.

Thanks !