diff options
author | Joshua Slack <[email protected]> | 2013-03-27 10:35:54 -0700 |
---|---|---|
committer | Joshua Slack <[email protected]> | 2013-03-27 10:35:54 -0700 |
commit | db666e6411c2395172c1da142654914459037900 (patch) | |
tree | 82ce9b5166ed6fe88f4cd13f1b4ca5dc2c9a1dfe /ardor3d-core/src/main/java | |
parent | b79aa24cc164775a65e9e0ad49ff6f4504a9b3fa (diff) | |
parent | 69bf5f9e34f2d6c94beb9265a1dbfd17e3a25205 (diff) |
Merge pull request #30 from gouessej/master
Fixes + enhancements
Diffstat (limited to 'ardor3d-core/src/main/java')
5 files changed, 50 insertions, 6 deletions
diff --git a/ardor3d-core/src/main/java/com/ardor3d/image/util/GeneratedImageFactory.java b/ardor3d-core/src/main/java/com/ardor3d/image/util/GeneratedImageFactory.java index 3591455..6316b57 100644 --- a/ardor3d-core/src/main/java/com/ardor3d/image/util/GeneratedImageFactory.java +++ b/ardor3d-core/src/main/java/com/ardor3d/image/util/GeneratedImageFactory.java @@ -171,6 +171,7 @@ public abstract class GeneratedImageFactory { } final ByteBuffer dataBuf = BufferUtils.createByteBuffer(data.length); dataBuf.put(data); + dataBuf.rewind(); dataList.add(dataBuf); } @@ -216,11 +217,12 @@ public abstract class GeneratedImageFactory { } } out.put(data); + out.rewind(); dataList.add(out); } - return new Image(useAlpha ? ImageDataFormat.RGBA : ImageDataFormat.RGB, PixelDataType.UnsignedByte, lumImage - .getWidth(), lumImage.getHeight(), dataList, null); + return new Image(useAlpha ? ImageDataFormat.RGBA : ImageDataFormat.RGB, PixelDataType.UnsignedByte, + lumImage.getWidth(), lumImage.getHeight(), dataList, null); } /** 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/RenderContext.java b/ardor3d-core/src/main/java/com/ardor3d/renderer/RenderContext.java index 83f3392..ef522a3 100644 --- a/ardor3d-core/src/main/java/com/ardor3d/renderer/RenderContext.java +++ b/ardor3d-core/src/main/java/com/ardor3d/renderer/RenderContext.java @@ -41,7 +41,7 @@ public class RenderContext { RenderState.StateType.class); protected final LineRecord _lineRecord = new LineRecord(); - protected final RendererRecord _rendererRecord = new RendererRecord(); + protected final RendererRecord _rendererRecord = createRendererRecord(); /** Basically this object represents the sharable portion of a GL context... Textures, displayLists, etc. */ protected final Object _glContextRep; @@ -64,6 +64,11 @@ public class RenderContext { _glContextRep = (shared == null) ? new Object() : shared._glContextRep; } + protected RendererRecord createRendererRecord() { + final RendererRecord rendererRecord = new RendererRecord(); + return rendererRecord; + } + protected void setupRecords() { for (final RenderState.StateType type : RenderState.StateType.values()) { _stateRecords.put(type, RenderState.createState(type).createStateRecord()); 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 { |