From 9f459af4e3ecd1a7b1c3432d8c4345cfd48ae74b Mon Sep 17 00:00:00 2001 From: Nehon Date: Sun, 28 Dec 2014 16:18:54 +0100 Subject: [PATCH] One can now call readFrameBuffer with a specific format, implementation has been done for the GLRenderer only. For now only placeholders have been done for the renderers that are still not using URA (all except LWJGL). --- .../renderer/android/OGLESShaderRenderer.java | 4 ++++ .../src/main/java/com/jme3/renderer/Renderer.java | 15 ++++++++++++++- .../java/com/jme3/renderer/opengl/GLRenderer.java | 11 ++++++++++- .../main/java/com/jme3/system/NullRenderer.java | 3 +++ .../jme3/renderer/ios/IGLESShaderRenderer.java | 4 ++++ .../java/com/jme3/renderer/jogl/JoglRenderer.java | 4 ++++ 6 files changed, 39 insertions(+), 2 deletions(-) diff --git a/jme3-android/src/main/java/com/jme3/renderer/android/OGLESShaderRenderer.java b/jme3-android/src/main/java/com/jme3/renderer/android/OGLESShaderRenderer.java index b12c7fea7..0d906abea 100644 --- a/jme3-android/src/main/java/com/jme3/renderer/android/OGLESShaderRenderer.java +++ b/jme3-android/src/main/java/com/jme3/renderer/android/OGLESShaderRenderer.java @@ -2564,4 +2564,8 @@ public class OGLESShaderRenderer implements Renderer { public void setLinearizeSrgbImages(boolean linearize) { //TODO once opglES3.0 is supported maybe.... } + + public void readFrameBufferWithFormat(FrameBuffer fb, ByteBuffer byteBuf, Image.Format format) { + throw new UnsupportedOperationException("Not supported yet. URA will make that work seamlessly"); + } } diff --git a/jme3-core/src/main/java/com/jme3/renderer/Renderer.java b/jme3-core/src/main/java/com/jme3/renderer/Renderer.java index a61b2185b..aa06d626e 100644 --- a/jme3-core/src/main/java/com/jme3/renderer/Renderer.java +++ b/jme3-core/src/main/java/com/jme3/renderer/Renderer.java @@ -222,7 +222,7 @@ public interface Renderer { /** * Reads the pixels currently stored in the specified framebuffer * into the given ByteBuffer object. - * Only color pixels are transferred, the format is BGRA with 8 bits + * Only color pixels are transferred, the format is RGBA with 8 bits * per component. The given byte buffer should have at least * fb.getWidth() * fb.getHeight() * 4 bytes remaining. * @@ -230,6 +230,19 @@ public interface Renderer { * @param byteBuf The bytebuffer to transfer color data to */ public void readFrameBuffer(FrameBuffer fb, ByteBuffer byteBuf); + + /** + * Reads the pixels currently stored in the specified framebuffer + * into the given ByteBuffer object. + * Only color pixels are transferred, witht hte given format. + * The given byte buffer should have at least + * fb.getWidth() * fb.getHeight() * 4 bytes remaining. + * + * @param fb The framebuffer to read from + * @param byteBuf The bytebuffer to transfer color data to + * @param format the image format to use when reading the frameBuffer. + */ + public void readFrameBufferWithFormat(FrameBuffer fb, ByteBuffer byteBuf, Image.Format format); /** * Deletes a framebuffer and all attached renderbuffers diff --git a/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java b/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java index 0eef936cb..e6526dce6 100644 --- a/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java +++ b/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java @@ -1629,6 +1629,10 @@ public class GLRenderer implements Renderer { } public void readFrameBuffer(FrameBuffer fb, ByteBuffer byteBuf) { + readFrameBufferWithGLFormat(fb, byteBuf, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE); + } + + private void readFrameBufferWithGLFormat(FrameBuffer fb, ByteBuffer byteBuf, int glFormat, int dataType) { if (fb != null) { RenderBuffer rb = fb.getColorBuffer(); if (rb == null) { @@ -1647,7 +1651,12 @@ public class GLRenderer implements Renderer { setFrameBuffer(null); } - gl.glReadPixels(vpX, vpY, vpW, vpH, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, byteBuf); + gl.glReadPixels(vpX, vpY, vpW, vpH, glFormat, dataType, byteBuf); + } + + public void readFrameBufferWithFormat(FrameBuffer fb, ByteBuffer byteBuf, Image.Format format) { + GLImageFormat glFormat = texUtil.getImageFormatWithError(format, false); + readFrameBufferWithGLFormat(fb, byteBuf, glFormat.format, glFormat.dataType); } private void deleteRenderBuffer(FrameBuffer fb, RenderBuffer rb) { diff --git a/jme3-core/src/main/java/com/jme3/system/NullRenderer.java b/jme3-core/src/main/java/com/jme3/system/NullRenderer.java index 20a946cee..06015ecd3 100644 --- a/jme3-core/src/main/java/com/jme3/system/NullRenderer.java +++ b/jme3-core/src/main/java/com/jme3/system/NullRenderer.java @@ -161,4 +161,7 @@ public class NullRenderer implements Renderer { public void setLinearizeSrgbImages(boolean linearize) { } + public void readFrameBufferWithFormat(FrameBuffer fb, ByteBuffer byteBuf, Image.Format format) { + } + } diff --git a/jme3-ios/src/main/java/com/jme3/renderer/ios/IGLESShaderRenderer.java b/jme3-ios/src/main/java/com/jme3/renderer/ios/IGLESShaderRenderer.java index 957569ddd..e0b6e0a08 100644 --- a/jme3-ios/src/main/java/com/jme3/renderer/ios/IGLESShaderRenderer.java +++ b/jme3-ios/src/main/java/com/jme3/renderer/ios/IGLESShaderRenderer.java @@ -2593,4 +2593,8 @@ public class IGLESShaderRenderer implements Renderer { public void setLinearizeSrgbImages(boolean linearize) { } + + public void readFrameBufferWithFormat(FrameBuffer fb, ByteBuffer byteBuf, Image.Format format) { + throw new UnsupportedOperationException("Not supported yet. URA will make that work seamlessly"); + } } \ No newline at end of file diff --git a/jme3-jogl/src/main/java/com/jme3/renderer/jogl/JoglRenderer.java b/jme3-jogl/src/main/java/com/jme3/renderer/jogl/JoglRenderer.java index f04e61a88..8fa9d144a 100644 --- a/jme3-jogl/src/main/java/com/jme3/renderer/jogl/JoglRenderer.java +++ b/jme3-jogl/src/main/java/com/jme3/renderer/jogl/JoglRenderer.java @@ -2713,4 +2713,8 @@ public class JoglRenderer implements Renderer { public void setLinearizeSrgbImages(boolean linearize) { linearizeSrgbImages = linearize; } + + public void readFrameBufferWithFormat(FrameBuffer fb, ByteBuffer byteBuf, Image.Format format) { + throw new UnsupportedOperationException("Not supported yet. URA will make that work seamlessly"); + } }