What’s the prevailing wisdom on how to draw bits of the scenegraph using OpenGL?
I’m not looking for anything particularly fancy: I’m quite happy without event/mouse integration or any of that stuff; I just want to draw rectangular areas of stuff with OpenGL rather than JavaFX primitives.
What I’m currently doing is (using LWJGL2.9.3) is using a Pbuffer, drawing whatever to it every frame using a JavaFX AnimationTimer, and then calling glReadPixels to read the rendered stuff back into a ByteBuffer.
I then feed the ByteBuffer data into a PixelWriter from an Image which is inside an ImageView node:
glReadPixels(0, 0, 800, 600, GL_BGRA, GL_UNSIGNED_BYTE, pixels);
PixelWriter pw = writableImage.getPixelWriter();
pw.setPixels(0, 0, 800, 600, javafx.scene.image.PixelFormat.getByteBgraInstance(), raw, 800 * 600 * 4 - 800 * 4, -800 * 4);
I’ve used some Unsafe hackery so that the “raw” array referred to there is actually being written directly into by glReadPixels, which I have to do because glReadPixels requires a direct ByteBuffer whereas setPixels only takes either a byte[] array or a heap ByteBuffer (irritating but not too hard to work around in the end). So that at least saves a fairly big copy.
Is there a better (more efficient) way than this?
Cas