diff options
author | Julien Gouesse <[email protected]> | 2013-03-09 13:01:16 +0100 |
---|---|---|
committer | Julien Gouesse <[email protected]> | 2013-03-09 13:01:16 +0100 |
commit | d558bdff0cc394ad536c4dc94a0871c6b73abfcc (patch) | |
tree | 4a41c0f02b351ed9a601f0bf94624adbbdba0d1f /ardor3d-core/src | |
parent | d2373e66e61f0d8e0b0e6f8e08379a9794bbc107 (diff) |
Uses the proper buffer size when using ScreenExporter with JOGL 2.0
Diffstat (limited to 'ardor3d-core/src')
3 files changed, 40 insertions, 3 deletions
diff --git a/ardor3d-core/src/main/java/com/ardor3d/renderer/AbstractRenderer.java b/ardor3d-core/src/main/java/com/ardor3d/renderer/AbstractRenderer.java index 6384842..8aa7f94 100644 --- a/ardor3d-core/src/main/java/com/ardor3d/renderer/AbstractRenderer.java +++ b/ardor3d-core/src/main/java/com/ardor3d/renderer/AbstractRenderer.java @@ -10,15 +10,19 @@ package com.ardor3d.renderer; +import java.nio.ByteBuffer; import java.util.EnumMap; import java.util.List; +import com.ardor3d.image.ImageDataFormat; +import com.ardor3d.image.PixelDataType; +import com.ardor3d.image.util.ImageUtils; import com.ardor3d.math.ColorRGBA; import com.ardor3d.math.type.ReadOnlyColorRGBA; import com.ardor3d.renderer.queue.RenderQueue; import com.ardor3d.renderer.state.RenderState; -import com.ardor3d.renderer.state.TextureState; import com.ardor3d.renderer.state.RenderState.StateType; +import com.ardor3d.renderer.state.TextureState; import com.ardor3d.renderer.state.record.RendererRecord; import com.ardor3d.scenegraph.FloatBufferData; import com.ardor3d.util.Constants; @@ -188,4 +192,17 @@ public abstract class AbstractRenderer implements Renderer { public void setRenderLogic(final RenderLogic renderLogic) { this.renderLogic = renderLogic; } + + @Override + public void grabScreenContents(final ByteBuffer store, final ImageDataFormat format, final int x, final int y, + final int w, final int h) { + grabScreenContents(store, format, PixelDataType.UnsignedByte, x, y, w, h); + } + + @Override + public int getExpectedBufferSizeToGrabScreenContents(final ImageDataFormat format, final PixelDataType type, + final int w, final int h) { + final int size = w * h * ImageUtils.getPixelByteSize(format, type); + return size; + } } diff --git a/ardor3d-core/src/main/java/com/ardor3d/renderer/Renderer.java b/ardor3d-core/src/main/java/com/ardor3d/renderer/Renderer.java index 4d14424..a5b0e10 100644 --- a/ardor3d-core/src/main/java/com/ardor3d/renderer/Renderer.java +++ b/ardor3d-core/src/main/java/com/ardor3d/renderer/Renderer.java @@ -16,6 +16,7 @@ import java.util.Collection; import java.util.List; import com.ardor3d.image.ImageDataFormat; +import com.ardor3d.image.PixelDataType; import com.ardor3d.image.Texture; import com.ardor3d.image.Texture1D; import com.ardor3d.image.Texture2D; @@ -182,6 +183,25 @@ public interface Renderer { */ void grabScreenContents(ByteBuffer store, ImageDataFormat format, int x, int y, int w, int h); + void grabScreenContents(final ByteBuffer store, final ImageDataFormat format, final PixelDataType type, + final int x, final int y, final int w, final int h); + + /** + * Gets the expected size (in bytes) of the buffer used to call <code>grabScreenContents</code> + * + * @param format + * the format to read in data for. + * @param type + * the format to read in data for. + * @param w + * - width of block + * @param h + * - height of block + * @return the expected size (in bytes) of the buffer used to call <code>grabScreenContents</code> + */ + int getExpectedBufferSizeToGrabScreenContents(final ImageDataFormat format, final PixelDataType type, final int w, + final int h); + /** * <code>draw</code> renders a scene. As it receives a base class of <code>Spatial</code> the renderer hands off * management of the scene to spatial for it to determine when a <code>Geometry</code> leaf is reached. diff --git a/ardor3d-core/src/main/java/com/ardor3d/util/screen/ScreenExporter.java b/ardor3d-core/src/main/java/com/ardor3d/util/screen/ScreenExporter.java index cd88e96..1b50d69 100644 --- a/ardor3d-core/src/main/java/com/ardor3d/util/screen/ScreenExporter.java +++ b/ardor3d-core/src/main/java/com/ardor3d/util/screen/ScreenExporter.java @@ -14,7 +14,6 @@ import java.nio.ByteBuffer; import com.ardor3d.image.ImageDataFormat; import com.ardor3d.image.PixelDataType; -import com.ardor3d.image.util.ImageUtils; import com.ardor3d.renderer.Camera; import com.ardor3d.renderer.Renderer; import com.ardor3d.util.geom.BufferUtils; @@ -29,7 +28,8 @@ public class ScreenExporter { final int width = camera.getWidth(), height = camera.getHeight(); // prepare our data buffer - final int size = width * height * ImageUtils.getPixelByteSize(format, PixelDataType.UnsignedByte); + final int size = renderer.getExpectedBufferSizeToGrabScreenContents(format, PixelDataType.UnsignedByte, width, + height); if (_scratch.capacity() < size) { _scratch = BufferUtils.createByteBuffer(size); } else { |