From 59a56df1e89076577753e9484e5c2bfb2a5115cd Mon Sep 17 00:00:00 2001 From: Julien Gouesse Date: Sat, 9 Mar 2013 10:09:22 +0100 Subject: Fixes GeneratedTexturesExample (several rewind() calls were missing in the API) --- .../src/main/java/com/ardor3d/image/util/GeneratedImageFactory.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'ardor3d-core/src/main/java') 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); } /** -- cgit v1.2.3 From d558bdff0cc394ad536c4dc94a0871c6b73abfcc Mon Sep 17 00:00:00 2001 From: Julien Gouesse Date: Sat, 9 Mar 2013 13:01:16 +0100 Subject: Uses the proper buffer size when using ScreenExporter with JOGL 2.0 --- .../java/com/ardor3d/renderer/AbstractRenderer.java | 19 ++++++++++++++++++- .../main/java/com/ardor3d/renderer/Renderer.java | 20 ++++++++++++++++++++ .../com/ardor3d/util/screen/ScreenExporter.java | 4 ++-- .../com/ardor3d/renderer/jogl/JoglRenderer.java | 21 ++++++++++++++++++--- .../com/ardor3d/renderer/lwjgl/LwjglRenderer.java | 8 +++++--- 5 files changed, 63 insertions(+), 9 deletions(-) (limited to 'ardor3d-core/src/main/java') 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 grabScreenContents + * + * @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 grabScreenContents + */ + int getExpectedBufferSizeToGrabScreenContents(final ImageDataFormat format, final PixelDataType type, final int w, + final int h); + /** * draw renders a scene. As it receives a base class of Spatial the renderer hands off * management of the scene to spatial for it to determine when a Geometry 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 { diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglRenderer.java b/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglRenderer.java index 43cd035..081c270 100644 --- a/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglRenderer.java +++ b/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglRenderer.java @@ -32,6 +32,7 @@ import javax.media.opengl.fixedfunc.GLPointerFunc; import javax.media.opengl.glu.GLU; 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; @@ -102,6 +103,7 @@ import com.ardor3d.util.Constants; import com.ardor3d.util.geom.BufferUtils; import com.ardor3d.util.stat.StatCollector; import com.ardor3d.util.stat.StatType; +import com.jogamp.opengl.util.GLBuffers; /** * JoglRenderer provides an implementation of the Renderer interface using the JOGL API. @@ -297,12 +299,25 @@ public class JoglRenderer extends AbstractRenderer { _inOrthoMode = false; } - public void grabScreenContents(final ByteBuffer store, final ImageDataFormat format, final int x, final int y, - final int w, final int h) { + @Override + public void grabScreenContents(final ByteBuffer store, final ImageDataFormat format, final PixelDataType type, + final int x, final int y, final int w, final int h) { final GL gl = GLContext.getCurrentGL(); final int pixFormat = JoglTextureUtil.getGLPixelFormat(format); - gl.glReadPixels(x, y, w, h, pixFormat, GL.GL_UNSIGNED_BYTE, store); + final int pixDataType = JoglTextureUtil.getGLPixelDataType(type); + // N.B: it expects depth = 1 & pack = true + gl.glReadPixels(x, y, w, h, pixFormat, pixDataType, store); + } + + @Override + public int getExpectedBufferSizeToGrabScreenContents(final ImageDataFormat format, final PixelDataType type, + final int w, final int h) { + final GL gl = GLContext.getCurrentGL(); + final int pixFormat = JoglTextureUtil.getGLPixelFormat(format); + final int pixDataType = JoglTextureUtil.getGLPixelDataType(type); + final int[] tmp = new int[1]; + return GLBuffers.sizeof(gl, tmp, pixFormat, pixDataType, w, h, 1, true); } public void draw(final Spatial s) { diff --git a/ardor3d-lwjgl/src/main/java/com/ardor3d/renderer/lwjgl/LwjglRenderer.java b/ardor3d-lwjgl/src/main/java/com/ardor3d/renderer/lwjgl/LwjglRenderer.java index d856465..72b7def 100644 --- a/ardor3d-lwjgl/src/main/java/com/ardor3d/renderer/lwjgl/LwjglRenderer.java +++ b/ardor3d-lwjgl/src/main/java/com/ardor3d/renderer/lwjgl/LwjglRenderer.java @@ -32,6 +32,7 @@ import org.lwjgl.opengl.GL31; import org.lwjgl.opengl.OpenGLException; 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; @@ -264,10 +265,11 @@ public class LwjglRenderer extends AbstractRenderer { _inOrthoMode = false; } - public void grabScreenContents(final ByteBuffer buff, final ImageDataFormat format, final int x, final int y, - final int w, final int h) { + public void grabScreenContents(final ByteBuffer buff, final ImageDataFormat format, final PixelDataType type, + final int x, final int y, final int w, final int h) { final int pixFormat = LwjglTextureUtil.getGLPixelFormat(format); - GL11.glReadPixels(x, y, w, h, pixFormat, GL11.GL_UNSIGNED_BYTE, buff); + final int pixDataType = LwjglTextureUtil.getGLPixelDataType(type); + GL11.glReadPixels(x, y, w, h, pixFormat, pixDataType, buff); } public void draw(final Spatial s) { -- cgit v1.2.3 From d664910383e7520e259ad13f0d204e1840e26a8e Mon Sep 17 00:00:00 2001 From: Julien Gouesse Date: Fri, 22 Mar 2013 00:00:14 +0100 Subject: Adds OpenGL-ES 2.0 support, prepares the use of PMVMatrix (work in progress) --- .../java/com/ardor3d/renderer/RenderContext.java | 7 ++++- .../ardor3d/framework/jogl/JoglCanvasRenderer.java | 3 +- .../renderer/jogl/JoglPbufferTextureRenderer.java | 2 +- .../ardor3d/renderer/jogl/JoglRenderContext.java | 35 ++++++++++++++++++++++ 4 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglRenderContext.java (limited to 'ardor3d-core/src/main/java') 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-jogl/src/main/java/com/ardor3d/framework/jogl/JoglCanvasRenderer.java b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglCanvasRenderer.java index 9c3b304..843970c 100644 --- a/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglCanvasRenderer.java +++ b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglCanvasRenderer.java @@ -38,6 +38,7 @@ import com.ardor3d.renderer.ContextManager; import com.ardor3d.renderer.RenderContext; import com.ardor3d.renderer.Renderer; import com.ardor3d.renderer.jogl.JoglContextCapabilities; +import com.ardor3d.renderer.jogl.JoglRenderContext; import com.ardor3d.renderer.jogl.JoglRenderer; import com.ardor3d.util.Ardor3dException; @@ -143,7 +144,7 @@ public class JoglCanvasRenderer implements CanvasRenderer { } final ContextCapabilities caps = createContextCapabilities(); - _currentContext = new RenderContext(_context, caps, sharedContext); + _currentContext = new JoglRenderContext(_context, caps, sharedContext); ContextManager.addContext(_context, _currentContext); ContextManager.switchContext(_context); diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglPbufferTextureRenderer.java b/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglPbufferTextureRenderer.java index a33664a..edfe5b5 100644 --- a/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglPbufferTextureRenderer.java +++ b/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglPbufferTextureRenderer.java @@ -279,7 +279,7 @@ public class JoglPbufferTextureRenderer extends AbstractPbufferTextureRenderer { final JoglContextCapabilities contextCaps = new JoglContextCapabilities(_pbuffer.getGL()); ContextManager.addContext(_context, - new RenderContext(_context, contextCaps, ContextManager.getCurrentContext())); + new JoglRenderContext(_context, contextCaps, ContextManager.getCurrentContext())); } catch (final Exception e) { logger.logp(Level.SEVERE, this.getClass().toString(), "initPbuffer()", "Exception", e); diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglRenderContext.java b/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglRenderContext.java new file mode 100644 index 0000000..6bf2aeb --- /dev/null +++ b/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglRenderContext.java @@ -0,0 +1,35 @@ +/** + * Copyright (c) 2008-2010 Ardor Labs, Inc. + * + * This file is part of Ardor3D. + * + * Ardor3D is free software: you can redistribute it and/or modify it + * under the terms of its license which may be found in the accompanying + * LICENSE file or at . + */ + +package com.ardor3d.renderer.jogl; + +import com.ardor3d.renderer.ContextCapabilities; +import com.ardor3d.renderer.RenderContext; +import com.ardor3d.renderer.state.record.RendererRecord; + +public class JoglRenderContext extends RenderContext { + + public JoglRenderContext(final Object key, final ContextCapabilities caps) { + this(key, caps, null); + } + + public JoglRenderContext(final Object key, final ContextCapabilities caps, final RenderContext shared) { + super(key, caps, shared); + } + + @Override + protected RendererRecord createRendererRecord() { + // TODO create a renderer record that performs glMatrixMode, glOrtho, glPushMatrix, glLoadMatrix, glPopMatrix, + // glMultMatrixf and glLoadMatrixf. Use PMVMatrix in a delegate + final RendererRecord rendererRecord = new RendererRecord(); + return rendererRecord; + } + +} -- cgit v1.2.3