aboutsummaryrefslogtreecommitdiffstats
path: root/ardor3d-jogl/src/main/java
diff options
context:
space:
mode:
authorJulien Gouesse <[email protected]>2013-10-11 22:01:09 +0200
committerJulien Gouesse <[email protected]>2013-10-11 22:01:09 +0200
commit11296d0d47ce63ab7fbf91aadb19730d5ea1612d (patch)
treed8fccdb547bee34834f4b23c688f24649b276a5d /ardor3d-jogl/src/main/java
parent44d441ea7b7ae51729f08e79146ef3142ce053f4 (diff)
Adds missing @Override annotations, fixes a few bugs and decreases the native memory footprint of the JOGL renderer
Diffstat (limited to 'ardor3d-jogl/src/main/java')
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglAwtCanvas.java3
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglCanvas.java18
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglCanvasRenderer.java24
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglNewtAwtCanvas.java3
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglNewtWindow.java3
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/input/jogl/JoglNewtKeyboardWrapper.java2
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglContextCapabilities.java25
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglPbufferTextureRenderer.java26
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglRenderContext.java16
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglRenderer.java173
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglTextureRenderer.java59
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglTextureRendererProvider.java7
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglFragmentProgramStateUtil.java10
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglShaderObjectsStateUtil.java70
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglTextureStateUtil.java50
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglVertexProgramStateUtil.java10
16 files changed, 358 insertions, 141 deletions
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglAwtCanvas.java b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglAwtCanvas.java
index defb510..b3c629c 100644
--- a/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglAwtCanvas.java
+++ b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglAwtCanvas.java
@@ -59,6 +59,7 @@ public class JoglAwtCanvas extends GLCanvas implements Canvas {
setAutoSwapBufferMode(false);
}
+ @Override
@MainThread
public void init() {
if (_inited) {
@@ -81,6 +82,7 @@ public class JoglAwtCanvas extends GLCanvas implements Canvas {
_inited = isRealized();
}
+ @Override
public void draw(final CountDownLatch latch) {
if (!_inited) {
init();
@@ -94,6 +96,7 @@ public class JoglAwtCanvas extends GLCanvas implements Canvas {
}
}
+ @Override
public JoglCanvasRenderer getCanvasRenderer() {
return _canvasRenderer;
}
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglCanvas.java b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglCanvas.java
index def1f49..d51acaa 100644
--- a/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglCanvas.java
+++ b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglCanvas.java
@@ -63,30 +63,31 @@ public class JoglCanvas extends Frame implements NativeCanvas {
}
@Override
- public void addKeyListener(final KeyListener l) {
+ public synchronized void addKeyListener(final KeyListener l) {
_glCanvas.addKeyListener(l);
}
@Override
- public void addMouseListener(final MouseListener l) {
+ public synchronized void addMouseListener(final MouseListener l) {
_glCanvas.addMouseListener(l);
}
@Override
- public void addMouseMotionListener(final MouseMotionListener l) {
+ public synchronized void addMouseMotionListener(final MouseMotionListener l) {
_glCanvas.addMouseMotionListener(l);
}
@Override
- public void addMouseWheelListener(final MouseWheelListener l) {
+ public synchronized void addMouseWheelListener(final MouseWheelListener l) {
_glCanvas.addMouseWheelListener(l);
}
@Override
- public void addFocusListener(final FocusListener l) {
+ public synchronized void addFocusListener(final FocusListener l) {
_glCanvas.addFocusListener(l);
}
+ @Override
@MainThread
public void init() {
privateInit();
@@ -226,6 +227,7 @@ public class JoglCanvas extends Frame implements NativeCanvas {
_inited = true;
}
+ @Override
public void draw(final CountDownLatch latch) {
if (!_inited) {
privateInit();
@@ -234,10 +236,12 @@ public class JoglCanvas extends Frame implements NativeCanvas {
_glCanvas.draw(latch);
}
+ @Override
public CanvasRenderer getCanvasRenderer() {
return _glCanvas.getCanvasRenderer();
}
+ @Override
public void close() {
try {
if (GLContext.getCurrent() != null) {
@@ -259,18 +263,22 @@ public class JoglCanvas extends Frame implements NativeCanvas {
return hasFocus();
}
+ @Override
public boolean isClosing() {
return _isClosing;
}
+ @Override
public void moveWindowTo(final int locX, final int locY) {
setLocation(locX, locY);
}
+ @Override
public void setIcon(final Image[] iconImages) {
// FIXME not implemented
}
+ @Override
public void setVSyncEnabled(final boolean enabled) {
_glCanvas.setVSyncEnabled(enabled);
}
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 1be8017..a86e3bc 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
@@ -40,6 +40,7 @@ import com.ardor3d.renderer.jogl.JoglContextCapabilities;
import com.ardor3d.renderer.jogl.JoglRenderContext;
import com.ardor3d.renderer.jogl.JoglRenderer;
import com.ardor3d.util.Ardor3dException;
+import com.ardor3d.util.geom.jogl.DirectNioBuffersSet;
public class JoglCanvasRenderer implements CanvasRenderer {
@@ -66,6 +67,8 @@ public class JoglCanvasRenderer implements CanvasRenderer {
protected CapsUtil _capsUtil;
+ protected DirectNioBuffersSet _directNioBuffersSet;
+
public JoglCanvasRenderer(final Scene scene) {
this(scene, false, new CapsUtil());
}
@@ -76,6 +79,7 @@ public class JoglCanvasRenderer implements CanvasRenderer {
_capsUtil = capsUtil;
}
+ @Override
public void makeCurrentContext() throws Ardor3dException {
int value = GLContext.CONTEXT_NOT_CURRENT;
int attempt = 0;
@@ -112,6 +116,7 @@ public class JoglCanvasRenderer implements CanvasRenderer {
}
}
+ @Override
public void releaseCurrentContext() {
if (_context.equals(GLContext.getCurrent())) {
try {
@@ -123,8 +128,8 @@ public class JoglCanvasRenderer implements CanvasRenderer {
}
@MainThread
- protected ContextCapabilities createContextCapabilities() {
- return new JoglContextCapabilities(_context.getGL());
+ protected JoglContextCapabilities createContextCapabilities() {
+ return new JoglContextCapabilities(_context.getGL(), _directNioBuffersSet);
}
@Override
@@ -132,6 +137,7 @@ public class JoglCanvasRenderer implements CanvasRenderer {
return new JoglRenderer();
}
+ @Override
@MainThread
public void init(final DisplaySettings settings, final boolean doSwap) {
_doSwap = doSwap;
@@ -141,6 +147,10 @@ public class JoglCanvasRenderer implements CanvasRenderer {
makeCurrentContext();
+ if (_directNioBuffersSet == null) {
+ _directNioBuffersSet = new DirectNioBuffersSet();
+ }
+
try {
// Look up a shared context, if a shared JoglCanvasRenderer is given.
@@ -151,7 +161,7 @@ public class JoglCanvasRenderer implements CanvasRenderer {
}
final ContextCapabilities caps = createContextCapabilities();
- _currentContext = new JoglRenderContext(_context, caps, sharedContext);
+ _currentContext = new JoglRenderContext(_context, caps, sharedContext, _directNioBuffersSet);
ContextManager.addContext(_context, _currentContext);
ContextManager.switchContext(_context);
@@ -199,6 +209,7 @@ public class JoglCanvasRenderer implements CanvasRenderer {
public int MAX_CONTEXT_GRAB_ATTEMPTS = 10;
+ @Override
@MainThread
public boolean draw() {
@@ -263,22 +274,27 @@ public class JoglCanvasRenderer implements CanvasRenderer {
return drew;
}
+ @Override
public Camera getCamera() {
return _camera;
}
+ @Override
public Scene getScene() {
return _scene;
}
+ @Override
public void setScene(final Scene scene) {
_scene = scene;
}
+ @Override
public Renderer getRenderer() {
return _renderer;
}
+ @Override
public void setCamera(final Camera camera) {
_camera = camera;
}
@@ -288,10 +304,12 @@ public class JoglCanvasRenderer implements CanvasRenderer {
return _currentContext;
}
+ @Override
public int getFrameClear() {
return _frameClear;
}
+ @Override
public void setFrameClear(final int buffers) {
_frameClear = buffers;
}
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglNewtAwtCanvas.java b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglNewtAwtCanvas.java
index f633f31..b56e6c1 100644
--- a/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglNewtAwtCanvas.java
+++ b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglNewtAwtCanvas.java
@@ -50,6 +50,7 @@ public class JoglNewtAwtCanvas extends NewtCanvasAWT implements Canvas, NewtWind
getNewtWindow().setAutoSwapBufferMode(false);
}
+ @Override
@MainThread
public void init() {
if (_inited) {
@@ -77,6 +78,7 @@ public class JoglNewtAwtCanvas extends NewtCanvasAWT implements Canvas, NewtWind
}
}
+ @Override
public void draw(final CountDownLatch latch) {
if (!_inited) {
init();
@@ -90,6 +92,7 @@ public class JoglNewtAwtCanvas extends NewtCanvasAWT implements Canvas, NewtWind
}
}
+ @Override
public JoglCanvasRenderer getCanvasRenderer() {
return _canvasRenderer;
}
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglNewtWindow.java b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglNewtWindow.java
index 1dc9dcc..4e2f3f4 100644
--- a/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglNewtWindow.java
+++ b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglNewtWindow.java
@@ -140,6 +140,7 @@ public class JoglNewtWindow implements NativeCanvas, NewtWindowContainer {
_newtWindow.setAutoSwapBufferMode(autoSwapBufferModeEnabled);
}
+ @Override
@MainThread
public void init() {
if (_inited) {
@@ -190,6 +191,7 @@ public class JoglNewtWindow implements NativeCanvas, NewtWindowContainer {
}
}
+ @Override
public void draw(final CountDownLatch latch) {
if (!_inited) {
init();
@@ -203,6 +205,7 @@ public class JoglNewtWindow implements NativeCanvas, NewtWindowContainer {
}
}
+ @Override
public JoglCanvasRenderer getCanvasRenderer() {
return _canvasRenderer;
}
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/input/jogl/JoglNewtKeyboardWrapper.java b/ardor3d-jogl/src/main/java/com/ardor3d/input/jogl/JoglNewtKeyboardWrapper.java
index 3f37c3e..bce6810 100644
--- a/ardor3d-jogl/src/main/java/com/ardor3d/input/jogl/JoglNewtKeyboardWrapper.java
+++ b/ardor3d-jogl/src/main/java/com/ardor3d/input/jogl/JoglNewtKeyboardWrapper.java
@@ -49,6 +49,7 @@ public class JoglNewtKeyboardWrapper extends KeyAdapter implements KeyboardWrapp
_newtWindow = Preconditions.checkNotNull(newtWindowContainer.getNewtWindow(), "newtWindow");
}
+ @Override
public void init() {
_newtWindow.addKeyListener(this);
_newtWindow.addWindowListener(new WindowAdapter() {
@@ -62,6 +63,7 @@ public class JoglNewtKeyboardWrapper extends KeyAdapter implements KeyboardWrapp
});
}
+ @Override
public synchronized PeekingIterator<KeyEvent> getEvents() {
if (_currentIterator == null || !_currentIterator.hasNext()) {
_currentIterator = new JoglNewtKeyboardIterator();
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglContextCapabilities.java b/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglContextCapabilities.java
index 3516e43..5ee1cb8 100644
--- a/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglContextCapabilities.java
+++ b/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglContextCapabilities.java
@@ -17,28 +17,29 @@ import javax.media.opengl.GL;
import javax.media.opengl.GL2;
import javax.media.opengl.GL2ES1;
import javax.media.opengl.GL2ES2;
-import javax.media.opengl.GL2GL3;
+import javax.media.opengl.GL2ES3;
import javax.media.opengl.GLAutoDrawable;
import com.ardor3d.renderer.ContextCapabilities;
-import com.ardor3d.util.geom.BufferUtils;
+import com.ardor3d.util.geom.jogl.DirectNioBuffersSet;
public class JoglContextCapabilities extends ContextCapabilities {
- public JoglContextCapabilities(final GLAutoDrawable autodrawable) {
- init(autodrawable.getGL());
+ public JoglContextCapabilities(final GLAutoDrawable autodrawable, final DirectNioBuffersSet directNioBuffersSet) {
+ init(autodrawable.getGL(), directNioBuffersSet);
}
- public JoglContextCapabilities(final GL gl) {
- init(gl);
+ public JoglContextCapabilities(final GL gl, final DirectNioBuffersSet directNioBuffersSet) {
+ init(gl, directNioBuffersSet);
}
public JoglContextCapabilities(final ContextCapabilities caps) {
super(caps);
}
- public void init(final GL gl) {
- final IntBuffer buf = BufferUtils.createIntBuffer(16);
+ public void init(final GL gl, final DirectNioBuffersSet directNioBuffersSet) {
+ final IntBuffer buf = directNioBuffersSet.getSingleIntBuffer();
+ buf.clear();
_supportsVBO = gl.isExtensionAvailable("GL_ARB_vertex_buffer_object");
_supportsGL1_2 = gl.isExtensionAvailable("GL_VERSION_1_2");
@@ -60,7 +61,7 @@ public class JoglContextCapabilities extends ContextCapabilities {
_supportsTextureLodBias = gl.isExtensionAvailable("GL_EXT_texture_lod_bias");
if (_supportsTextureLodBias) {
- gl.glGetIntegerv(GL2GL3.GL_MAX_TEXTURE_LOD_BIAS, buf);
+ gl.glGetIntegerv(GL2ES3.GL_MAX_TEXTURE_LOD_BIAS, buf);
_maxTextureLodBias = buf.get(0);
} else {
_maxTextureLodBias = 0f;
@@ -105,7 +106,7 @@ public class JoglContextCapabilities extends ContextCapabilities {
// Max multisample samples.
if (gl.isExtensionAvailable("GL_EXT_framebuffer_multisample")
&& gl.isExtensionAvailable("GL_EXT_framebuffer_blit")) {
- gl.glGetIntegerv(GL2GL3.GL_MAX_SAMPLES, buf);
+ gl.glGetIntegerv(GL2ES3.GL_MAX_SAMPLES, buf);
_maxFBOSamples = buf.get(0);
} else {
_maxFBOSamples = 0;
@@ -200,8 +201,8 @@ public class JoglContextCapabilities extends ContextCapabilities {
_supportsAniso = gl.isExtensionAvailable("GL_EXT_texture_filter_anisotropic");
if (_supportsAniso) {
- final FloatBuffer max_a = BufferUtils.createFloatBuffer(1);
- max_a.rewind();
+ final FloatBuffer max_a = directNioBuffersSet.getSingleFloatBuffer();
+ max_a.clear();
// Grab the maximum anisotropic filter.
gl.glGetFloatv(GL.GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, max_a);
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 2b877ee..119a6e7 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
@@ -41,7 +41,7 @@ import com.ardor3d.scene.state.jogl.util.JoglTextureUtil;
import com.ardor3d.scenegraph.Spatial;
import com.ardor3d.util.Ardor3dException;
import com.ardor3d.util.TextureKey;
-import com.ardor3d.util.geom.BufferUtils;
+import com.ardor3d.util.geom.jogl.DirectNioBuffersSet;
/**
* <p>
@@ -65,6 +65,8 @@ public class JoglPbufferTextureRenderer extends AbstractPbufferTextureRenderer {
// HACK: needed to get the parent context in here somehow...
public static GLContext _parentContext;
+ protected DirectNioBuffersSet _directNioBuffersSet;
+
public JoglPbufferTextureRenderer(final DisplaySettings settings, final Renderer parentRenderer,
final ContextCapabilities caps) {
super(settings, parentRenderer, caps);
@@ -76,6 +78,7 @@ public class JoglPbufferTextureRenderer extends AbstractPbufferTextureRenderer {
* <code>setupTexture</code> initializes a new Texture object for use with TextureRenderer. Generates a valid gl
* texture id for this texture and inits the data type for the texture.
*/
+ @Override
public void setupTexture(final Texture tex) {
if (tex.getType() != Type.TwoDimensional) {
throw new IllegalArgumentException("Unsupported type: " + tex.getType());
@@ -93,7 +96,7 @@ public class JoglPbufferTextureRenderer extends AbstractPbufferTextureRenderer {
}
// Create the texture
- final IntBuffer ibuf = BufferUtils.createIntBuffer(1);
+ final IntBuffer ibuf = _directNioBuffersSet.getSingleIntBuffer();
gl.glGenTextures(1, ibuf);
final int textureId = ibuf.get(0);
tex.setTextureIdForContext(context.getGlContextRep(), textureId);
@@ -115,14 +118,17 @@ public class JoglPbufferTextureRenderer extends AbstractPbufferTextureRenderer {
logger.fine("setup pbuffer tex" + textureId + ": " + _width + "," + _height);
}
+ @Override
public void render(final Spatial spat, final Texture tex, final int clear) {
render(null, spat, null, tex, clear);
}
+ @Override
public void render(final List<? extends Spatial> spat, final Texture tex, final int clear) {
render(spat, null, null, tex, clear);
}
+ @Override
public void render(final Scene scene, final Texture tex, final int clear) {
render(null, null, scene, tex, clear);
}
@@ -184,14 +190,17 @@ public class JoglPbufferTextureRenderer extends AbstractPbufferTextureRenderer {
// FIXME
}
+ @Override
public void render(final Spatial spat, final List<Texture> texs, final int clear) {
render(null, spat, null, texs, clear);
}
+ @Override
public void render(final List<? extends Spatial> spat, final List<Texture> texs, final int clear) {
render(spat, null, null, texs, clear);
}
+ @Override
public void render(final Scene scene, final List<Texture> texs, final int clear) {
render(null, null, scene, texs, clear);
}
@@ -247,6 +256,7 @@ public class JoglPbufferTextureRenderer extends AbstractPbufferTextureRenderer {
}
}
+ @Override
public void copyToTexture(final Texture tex, final int x, final int y, final int width, final int height,
final int xoffset, final int yoffset) {
final GL gl = GLContext.getCurrentGL();
@@ -293,9 +303,15 @@ public class JoglPbufferTextureRenderer extends AbstractPbufferTextureRenderer {
_context.makeCurrent();
- final JoglContextCapabilities contextCaps = new JoglContextCapabilities(_offscreenDrawable.getGL());
+ if (_directNioBuffersSet == null) {
+ _directNioBuffersSet = new DirectNioBuffersSet();
+ }
+
+ final JoglContextCapabilities contextCaps = new JoglContextCapabilities(_offscreenDrawable.getGL(),
+ _directNioBuffersSet);
ContextManager.addContext(_context,
- new JoglRenderContext(_context, contextCaps, ContextManager.getCurrentContext()));
+ new JoglRenderContext(_context, contextCaps, ContextManager.getCurrentContext(),
+ _directNioBuffersSet));
} catch (final Exception e) {
logger.logp(Level.SEVERE, this.getClass().toString(), "initPbuffer()", "Exception", e);
@@ -358,11 +374,13 @@ public class JoglPbufferTextureRenderer extends AbstractPbufferTextureRenderer {
ContextManager.switchContext(_oldContext.getContextKey());
}
+ @Override
public void cleanup() {
ContextManager.removeContext(_offscreenDrawable.getContext());
_offscreenDrawable.destroy();
}
+ @Override
public void setMultipleTargets(final boolean force) {
if (force) {
logger.fine("Copy Texture Pbuffer used!");
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
index faf3761..6dbd1d6 100644
--- a/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglRenderContext.java
+++ b/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglRenderContext.java
@@ -13,15 +13,21 @@ package com.ardor3d.renderer.jogl;
import com.ardor3d.renderer.ContextCapabilities;
import com.ardor3d.renderer.RenderContext;
import com.ardor3d.renderer.jogl.state.record.JoglRendererRecord;
+import com.ardor3d.util.geom.jogl.DirectNioBuffersSet;
public class JoglRenderContext extends RenderContext {
- public JoglRenderContext(final Object key, final ContextCapabilities caps) {
- this(key, caps, null);
+ private final DirectNioBuffersSet _directNioBuffersSet;
+
+ public JoglRenderContext(final Object key, final ContextCapabilities caps,
+ final DirectNioBuffersSet directNioBuffersSet) {
+ this(key, caps, null, directNioBuffersSet);
}
- public JoglRenderContext(final Object key, final ContextCapabilities caps, final RenderContext shared) {
+ public JoglRenderContext(final Object key, final ContextCapabilities caps, final RenderContext shared,
+ final DirectNioBuffersSet directNioBuffersSet) {
super(key, caps, shared);
+ _directNioBuffersSet = directNioBuffersSet;
}
@Override
@@ -30,6 +36,10 @@ public class JoglRenderContext extends RenderContext {
return rendererRecord;
}
+ public DirectNioBuffersSet getDirectNioBuffersSet() {
+ return _directNioBuffersSet;
+ }
+
@Override
public JoglRendererRecord getRendererRecord() {
return (JoglRendererRecord) _rendererRecord;
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 2d6b357..9dcdde4 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
@@ -23,6 +23,7 @@ import javax.media.opengl.GL;
import javax.media.opengl.GL2;
import javax.media.opengl.GL2ES1;
import javax.media.opengl.GL2ES2;
+import javax.media.opengl.GL2ES3;
import javax.media.opengl.GL2GL3;
import javax.media.opengl.GLContext;
import javax.media.opengl.GLException;
@@ -114,7 +115,7 @@ import com.jogamp.opengl.util.GLBuffers;
public class JoglRenderer extends AbstractRenderer {
private static final Logger logger = Logger.getLogger(JoglRenderer.class.getName());
- private final FloatBuffer _transformBuffer = BufferUtils.createFloatBuffer(16);
+ private FloatBuffer _transformBuffer;
private final Matrix4 _transformMatrix = new Matrix4();
/**
@@ -124,6 +125,7 @@ public class JoglRenderer extends AbstractRenderer {
logger.fine("JoglRenderer created.");
}
+ @Override
public void setBackgroundColor(final ReadOnlyColorRGBA c) {
final GL gl = GLContext.getCurrentGL();
@@ -157,14 +159,17 @@ public class JoglRenderer extends AbstractRenderer {
/**
* clear the render queue
*/
+ @Override
public void clearQueue() {
_queue.clearBuckets();
}
+ @Override
public void clearBuffers(final int buffers) {
clearBuffers(buffers, false);
}
+ @Override
public void clearBuffers(final int buffers, final boolean strict) {
final GL gl = GLContext.getCurrentGL();
@@ -216,6 +221,7 @@ public class JoglRenderer extends AbstractRenderer {
}
}
+ @Override
public void flushFrame(final boolean doSwap) {
final GL gl = GLContext.getCurrentGL();
@@ -242,6 +248,7 @@ public class JoglRenderer extends AbstractRenderer {
}
}
+ @Override
public void setOrtho() {
if (_inOrthoMode) {
throw new Ardor3dException("Already in Orthographic mode.");
@@ -263,6 +270,7 @@ public class JoglRenderer extends AbstractRenderer {
_inOrthoMode = true;
}
+ @Override
public void unsetOrtho() {
if (!_inOrthoMode) {
throw new Ardor3dException("Not in Orthographic mode.");
@@ -299,12 +307,14 @@ public class JoglRenderer extends AbstractRenderer {
return GLBuffers.sizeof(gl, tmp, pixFormat, pixDataType, w, h, 1, true);
}
+ @Override
public void draw(final Spatial s) {
if (s != null) {
s.onDraw(this);
}
}
+ @Override
public boolean checkAndAdd(final Spatial s) {
final RenderBucketType rqMode = s.getSceneHints().getRenderBucketType();
if (rqMode != RenderBucketType.Skip) {
@@ -321,18 +331,21 @@ public class JoglRenderer extends AbstractRenderer {
// Nothing to do here yet
}
+ @Override
public void flushGraphics() {
final GL gl = GLContext.getCurrentGL();
gl.glFlush();
}
+ @Override
public void finishGraphics() {
final GL gl = GLContext.getCurrentGL();
gl.glFinish();
}
+ @Override
public void applyNormalsMode(final NormalsMode normalsMode, final ReadOnlyTransform worldTransform) {
final GL gl = GLContext.getCurrentGL();
final RenderContext context = ContextManager.getCurrentContext();
@@ -417,31 +430,46 @@ public class JoglRenderer extends AbstractRenderer {
}
}
+ @Override
public void applyDefaultColor(final ReadOnlyColorRGBA defaultColor) {
final GL gl = GLContext.getCurrentGL();
- if (defaultColor != null) {
- gl.getGL2ES1().glColor4f(defaultColor.getRed(), defaultColor.getGreen(), defaultColor.getBlue(),
- defaultColor.getAlpha());
- } else {
- gl.getGL2ES1().glColor4f(1, 1, 1, 1);
+ if (gl.isGL2ES1()) {
+ if (defaultColor != null) {
+ gl.getGL2ES1().glColor4f(defaultColor.getRed(), defaultColor.getGreen(), defaultColor.getBlue(),
+ defaultColor.getAlpha());
+ } else {
+ gl.getGL2ES1().glColor4f(1, 1, 1, 1);
+ }
}
}
+ @Override
public void deleteVBOs(final Collection<Integer> ids) {
final GL gl = GLContext.getCurrentGL();
- final IntBuffer idBuffer = BufferUtils.createIntBuffer(ids.size());
- idBuffer.clear();
+
+ final JoglRenderContext context = (JoglRenderContext) ContextManager.getCurrentContext();
+ final IntBuffer vboIdsBuffer = context.getDirectNioBuffersSet().getVboIdsBuffer();
+ vboIdsBuffer.clear();
for (final Integer i : ids) {
+ if (!vboIdsBuffer.hasRemaining()) {
+ vboIdsBuffer.flip();
+ if (vboIdsBuffer.remaining() > 0) {
+ gl.glDeleteTextures(vboIdsBuffer.remaining(), vboIdsBuffer);
+ }
+ vboIdsBuffer.clear();
+ }
if (i != null && i != 0) {
- idBuffer.put(i);
+ vboIdsBuffer.put(i);
}
}
- idBuffer.flip();
- if (idBuffer.remaining() > 0) {
- gl.glDeleteBuffers(idBuffer.remaining(), idBuffer);
+ vboIdsBuffer.flip();
+ if (vboIdsBuffer.remaining() > 0) {
+ gl.glDeleteTextures(vboIdsBuffer.remaining(), vboIdsBuffer);
}
+ vboIdsBuffer.clear();
}
+ @Override
public void deleteDisplayLists(final Collection<Integer> ids) {
final GL gl = GLContext.getCurrentGL();
for (final Integer i : ids) {
@@ -451,6 +479,7 @@ public class JoglRenderer extends AbstractRenderer {
}
}
+ @Override
public void deleteVBOs(final AbstractBufferData<?> buffer) {
if (buffer == null) {
return;
@@ -459,7 +488,7 @@ public class JoglRenderer extends AbstractRenderer {
final GL gl = GLContext.getCurrentGL();
// ask for the current state record
- final RenderContext context = ContextManager.getCurrentContext();
+ final JoglRenderContext context = (JoglRenderContext) ContextManager.getCurrentContext();
final int id = buffer.getVBOID(context.getGlContextRep());
if (id == 0) {
@@ -469,17 +498,20 @@ public class JoglRenderer extends AbstractRenderer {
buffer.removeVBOID(context.getGlContextRep());
- final IntBuffer idBuff = BufferUtils.createIntBuffer(1);
+ final IntBuffer idBuff = context.getDirectNioBuffersSet().getSingleIntBuffer();
+ idBuff.clear();
idBuff.put(id);
idBuff.flip();
gl.glDeleteBuffers(1, idBuff);
}
+ @Override
public void updateTexture1DSubImage(final Texture1D destination, final int dstOffsetX, final int dstWidth,
final ByteBuffer source, final int srcOffsetX) {
updateTexSubImage(destination, dstOffsetX, 0, 0, dstWidth, 0, 0, source, srcOffsetX, 0, 0, 0, 0, null);
}
+ @Override
public void updateTexture2DSubImage(final Texture2D destination, final int dstOffsetX, final int dstOffsetY,
final int dstWidth, final int dstHeight, final ByteBuffer source, final int srcOffsetX,
final int srcOffsetY, final int srcTotalWidth) {
@@ -487,6 +519,7 @@ public class JoglRenderer extends AbstractRenderer {
srcOffsetY, 0, srcTotalWidth, 0, null);
}
+ @Override
public void updateTexture3DSubImage(final Texture3D destination, final int dstOffsetX, final int dstOffsetY,
final int dstOffsetZ, final int dstWidth, final int dstHeight, final int dstDepth, final ByteBuffer source,
final int srcOffsetX, final int srcOffsetY, final int srcOffsetZ, final int srcTotalWidth,
@@ -495,6 +528,7 @@ public class JoglRenderer extends AbstractRenderer {
srcOffsetX, srcOffsetY, srcOffsetZ, srcTotalWidth, srcTotalHeight, null);
}
+ @Override
public void updateTextureCubeMapSubImage(final TextureCubeMap destination, final TextureCubeMap.Face dstFace,
final int dstOffsetX, final int dstOffsetY, final int dstWidth, final int dstHeight,
final ByteBuffer source, final int srcOffsetX, final int srcOffsetY, final int srcTotalWidth) {
@@ -578,10 +612,10 @@ public class JoglRenderer extends AbstractRenderer {
gl.glPixelStorei(GL2ES2.GL_UNPACK_SKIP_ROWS, srcOffsetY);
}
if (origImageHeight != imageHeight) {
- gl.glPixelStorei(GL2GL3.GL_UNPACK_IMAGE_HEIGHT, imageHeight);
+ gl.glPixelStorei(GL2ES3.GL_UNPACK_IMAGE_HEIGHT, imageHeight);
}
if (origSkipImages != srcOffsetZ) {
- gl.glPixelStorei(GL2GL3.GL_UNPACK_SKIP_IMAGES, srcOffsetZ);
+ gl.glPixelStorei(GL2ES3.GL_UNPACK_SKIP_IMAGES, srcOffsetZ);
}
// Upload the image region into the texture.
@@ -626,15 +660,16 @@ public class JoglRenderer extends AbstractRenderer {
}
// Restore image height.
if (origImageHeight != imageHeight) {
- gl.glPixelStorei(GL2GL3.GL_UNPACK_IMAGE_HEIGHT, origImageHeight);
+ gl.glPixelStorei(GL2ES3.GL_UNPACK_IMAGE_HEIGHT, origImageHeight);
}
// Restore skip images.
if (origSkipImages != srcOffsetZ) {
- gl.glPixelStorei(GL2GL3.GL_UNPACK_SKIP_IMAGES, origSkipImages);
+ gl.glPixelStorei(GL2ES3.GL_UNPACK_SKIP_IMAGES, origSkipImages);
}
}
}
+ @Override
public void checkCardError() throws Ardor3dException {
final GL gl = GLContext.getCurrentGL();
final GLU glu = new GLU();
@@ -649,6 +684,7 @@ public class JoglRenderer extends AbstractRenderer {
}
}
+ @Override
public void draw(final Renderable renderable) {
if (renderLogic != null) {
renderLogic.apply(renderable);
@@ -659,14 +695,20 @@ public class JoglRenderer extends AbstractRenderer {
}
}
+ @Override
public boolean doTransforms(final ReadOnlyTransform transform) {
// set world matrix
if (!transform.isIdentity()) {
synchronized (_transformMatrix) {
+ final JoglRenderContext context = (JoglRenderContext) ContextManager.getCurrentContext();
+ if (_transformBuffer == null) {
+ _transformBuffer = context.getDirectNioBuffersSet().getTransformBuffer();
+ }
+ _transformBuffer.clear();
+
transform.getGLApplyMatrix(_transformBuffer);
- final JoglRendererRecord matRecord = (JoglRendererRecord) ContextManager.getCurrentContext()
- .getRendererRecord();
+ final JoglRendererRecord matRecord = context.getRendererRecord();
JoglRendererUtil.switchMode(matRecord, GLMatrixFunc.GL_MODELVIEW);
matRecord.getMatrixBackend().pushMatrix();
matRecord.getMatrixBackend().multMatrix(_transformBuffer);
@@ -676,13 +718,15 @@ public class JoglRenderer extends AbstractRenderer {
return false;
}
+ @Override
public void undoTransforms(final ReadOnlyTransform transform) {
- final JoglRendererRecord matRecord = (JoglRendererRecord) ContextManager.getCurrentContext()
- .getRendererRecord();
+ final JoglRenderContext context = (JoglRenderContext) ContextManager.getCurrentContext();
+ final JoglRendererRecord matRecord = context.getRendererRecord();
JoglRendererUtil.switchMode(matRecord, GLMatrixFunc.GL_MODELVIEW);
matRecord.getMatrixBackend().popMatrix();
}
+ @Override
public void setupVertexData(final FloatBufferData vertexBufferData) {
final GL gl = GLContext.getCurrentGL();
@@ -697,12 +741,13 @@ public class JoglRenderer extends AbstractRenderer {
gl.getGL2GL3().glEnableClientState(GLPointerFunc.GL_VERTEX_ARRAY);
}
vertexBuffer.rewind();
- if (gl.isGL2ES1()) {
+ if (gl.isGL2ES1() && vertexBufferData != null) {
gl.getGL2ES1().glVertexPointer(vertexBufferData.getValuesPerTuple(), GL.GL_FLOAT, 0, vertexBuffer);
}
}
}
+ @Override
public void setupNormalData(final FloatBufferData normalBufferData) {
final GL gl = GLContext.getCurrentGL();
@@ -723,6 +768,7 @@ public class JoglRenderer extends AbstractRenderer {
}
}
+ @Override
public void setupColorData(final FloatBufferData colorBufferData) {
final GL gl = GLContext.getCurrentGL();
@@ -737,32 +783,31 @@ public class JoglRenderer extends AbstractRenderer {
gl.getGL2GL3().glEnableClientState(GLPointerFunc.GL_COLOR_ARRAY);
}
colorBuffer.rewind();
- if (gl.isGL2ES1()) {
+ if (gl.isGL2ES1() && colorBufferData != null) {
gl.getGL2ES1().glColorPointer(colorBufferData.getValuesPerTuple(), GL.GL_FLOAT, 0, colorBuffer);
}
}
}
+ @Override
public void setupFogData(final FloatBufferData fogBufferData) {
final GL gl = GLContext.getCurrentGL();
final FloatBuffer fogBuffer = fogBufferData != null ? fogBufferData.getBuffer() : null;
- if (fogBuffer == null) {
- if (gl.isGL2GL3()) {
- gl.getGL2GL3().glDisableClientState(GL2.GL_FOG_COORDINATE_ARRAY);
- }
- } else {
- if (gl.isGL2GL3()) {
- gl.getGL2GL3().glEnableClientState(GL2.GL_FOG_COORDINATE_ARRAY);
- }
- fogBuffer.rewind();
- if (gl.isGL2()) {
+ if (gl.isGL2()) {
+ if (fogBuffer == null) {
+ gl.getGL2().glDisableClientState(GL2.GL_FOG_COORDINATE_ARRAY);
+ } else {
+ gl.getGL2().glEnableClientState(GL2.GL_FOG_COORDINATE_ARRAY);
+ fogBuffer.rewind();
gl.getGL2().glFogCoordPointer(GL.GL_FLOAT, 0, fogBuffer);
}
}
+
}
+ @Override
public void setupTextureData(final List<FloatBufferData> textureCoords) {
final GL gl = GLContext.getCurrentGL();
@@ -811,6 +856,7 @@ public class JoglRenderer extends AbstractRenderer {
enabledTextures |= (2 << i);
}
+ @SuppressWarnings("null")
final FloatBufferData textureBufferData = textureCoords.get(i);
final FloatBuffer textureBuffer = textureBufferData.getBuffer();
@@ -830,6 +876,7 @@ public class JoglRenderer extends AbstractRenderer {
rendRecord.setTexturesValid(true);
}
+ @Override
public void drawElements(final IndexBufferData<?> indices, final int[] indexLengths, final IndexMode[] indexModes,
final int primcount) {
if (indices == null || indices.getBuffer() == null) {
@@ -971,6 +1018,7 @@ public class JoglRenderer extends AbstractRenderer {
return vboID;
}
+ @Override
public void setupVertexDataVBO(final FloatBufferData data) {
final GL gl = GLContext.getCurrentGL();
@@ -994,6 +1042,7 @@ public class JoglRenderer extends AbstractRenderer {
}
}
+ @Override
public void setupNormalDataVBO(final FloatBufferData data) {
final GL gl = GLContext.getCurrentGL();
@@ -1017,6 +1066,7 @@ public class JoglRenderer extends AbstractRenderer {
}
}
+ @Override
public void setupColorDataVBO(final FloatBufferData data) {
final GL gl = GLContext.getCurrentGL();
@@ -1040,6 +1090,7 @@ public class JoglRenderer extends AbstractRenderer {
}
}
+ @Override
public void setupFogDataVBO(final FloatBufferData data) {
final GL gl = GLContext.getCurrentGL();
@@ -1068,6 +1119,7 @@ public class JoglRenderer extends AbstractRenderer {
}
}
+ @Override
public void setupTextureDataVBO(final List<FloatBufferData> textureCoords) {
final GL gl = GLContext.getCurrentGL();
@@ -1106,6 +1158,7 @@ public class JoglRenderer extends AbstractRenderer {
checkAndSetTextureArrayUnit(i, gl, rendRecord, caps);
// grab a vboID and make sure it exists and is up to date.
+ @SuppressWarnings("null")
final FloatBufferData data = textureCoords.get(i);
final int vboID = setupVBO(data, context);
@@ -1149,6 +1202,7 @@ public class JoglRenderer extends AbstractRenderer {
rendRecord.setTexturesValid(true);
}
+ @Override
public void setupInterleavedDataVBO(final FloatBufferData interleaved, final FloatBufferData vertexCoords,
final FloatBufferData normalCoords, final FloatBufferData colorCoords,
final List<FloatBufferData> textureCoords) {
@@ -1216,7 +1270,7 @@ public class JoglRenderer extends AbstractRenderer {
TextureState.MAX_TEXTURES) : 1;
for (int i = 0; i < max; i++) {
wasOn = (enabledTextures & (2 << i)) != 0;
- exists = textureCoords != null && i < textureCoords.size() && textureCoords.get(i) != null
+ exists = i < textureCoords.size() && textureCoords.get(i) != null
&& i <= ts.getMaxTextureIndexUsed();
if (!exists) {
@@ -1282,6 +1336,7 @@ public class JoglRenderer extends AbstractRenderer {
}
}
+ @SuppressWarnings("null")
private void initializeInterleavedVBO(final RenderContext context, final FloatBufferData interleaved,
final FloatBufferData vertexCoords, final FloatBufferData normalCoords, final FloatBufferData colorCoords,
final List<FloatBufferData> textureCoords, final int bufferSize) {
@@ -1321,7 +1376,7 @@ public class JoglRenderer extends AbstractRenderer {
final TextureState ts = (TextureState) context.getCurrentState(RenderState.StateType.Texture);
if (ts != null) {
for (int i = 0; i <= ts.getMaxTextureIndexUsed() && i < caps.getNumberOfFragmentTexCoordUnits(); i++) {
- if (textureCoords == null || i >= textureCoords.size()) {
+ if (i >= textureCoords.size()) {
continue;
}
@@ -1344,6 +1399,7 @@ public class JoglRenderer extends AbstractRenderer {
interleaved.setNeedsRefresh(false);
}
+ @Override
public void drawElementsVBO(final IndexBufferData<?> indices, final int[] indexLengths,
final IndexMode[] indexModes, final int primcount) {
final GL gl = GLContext.getCurrentGL();
@@ -1410,6 +1466,7 @@ public class JoglRenderer extends AbstractRenderer {
}
}
+ @Override
public void drawArrays(final FloatBufferData vertexBuffer, final int[] indexLengths, final IndexMode[] indexModes,
final int primcount) {
final GL gl = GLContext.getCurrentGL();
@@ -1460,11 +1517,15 @@ public class JoglRenderer extends AbstractRenderer {
private static int makeVBOId() {
final GL gl = GLContext.getCurrentGL();
- final IntBuffer idBuff = BufferUtils.createIntBuffer(1);
+ final JoglRenderContext context = (JoglRenderContext) ContextManager.getCurrentContext();
+
+ final IntBuffer idBuff = context.getDirectNioBuffersSet().getSingleIntBuffer();
+ idBuff.clear();
gl.glGenBuffers(1, idBuff);
return idBuff.get(0);
}
+ @Override
public void unbindVBO() {
final RenderContext context = ContextManager.getCurrentContext();
final RendererRecord rendRecord = context.getRendererRecord();
@@ -1479,28 +1540,28 @@ public class JoglRenderer extends AbstractRenderer {
glMode = GL.GL_STATIC_DRAW;
break;
case StaticRead:
- glMode = GL2GL3.GL_STATIC_READ;
+ glMode = GL2ES3.GL_STATIC_READ;
break;
case StaticCopy:
- glMode = GL2GL3.GL_STATIC_COPY;
+ glMode = GL2ES3.GL_STATIC_COPY;
break;
case DynamicDraw:
glMode = GL.GL_DYNAMIC_DRAW;
break;
case DynamicRead:
- glMode = GL2GL3.GL_DYNAMIC_READ;
+ glMode = GL2ES3.GL_DYNAMIC_READ;
break;
case DynamicCopy:
- glMode = GL2GL3.GL_DYNAMIC_COPY;
+ glMode = GL2ES3.GL_DYNAMIC_COPY;
break;
case StreamDraw:
glMode = GL2ES2.GL_STREAM_DRAW;
break;
case StreamRead:
- glMode = GL2GL3.GL_STREAM_READ;
+ glMode = GL2ES3.GL_STREAM_READ;
break;
case StreamCopy:
- glMode = GL2GL3.GL_STREAM_COPY;
+ glMode = GL2ES3.GL_STREAM_COPY;
break;
}
return glMode;
@@ -1519,7 +1580,7 @@ public class JoglRenderer extends AbstractRenderer {
glMode = GL.GL_TRIANGLE_FAN;
break;
case Quads:
- glMode = GL2.GL_QUADS;
+ glMode = GL2GL3.GL_QUADS;
break;
case QuadStrip:
glMode = GL2.GL_QUAD_STRIP;
@@ -1552,6 +1613,7 @@ public class JoglRenderer extends AbstractRenderer {
throw new IllegalArgumentException("Unknown buffer type: " + indices.getBuffer());
}
+ @Override
public void setModelViewMatrix(final FloatBuffer matrix) {
final JoglRendererRecord matRecord = (JoglRendererRecord) ContextManager.getCurrentContext()
.getRendererRecord();
@@ -1560,6 +1622,7 @@ public class JoglRenderer extends AbstractRenderer {
loadMatrix(matrix);
}
+ @Override
public void setProjectionMatrix(final FloatBuffer matrix) {
final JoglRendererRecord matRecord = (JoglRendererRecord) ContextManager.getCurrentContext()
.getRendererRecord();
@@ -1574,34 +1637,38 @@ public class JoglRenderer extends AbstractRenderer {
matRecord.getMatrixBackend().loadMatrix(matrix);
}
+ @Override
public FloatBuffer getModelViewMatrix(final FloatBuffer store) {
return getMatrix(GLMatrixFunc.GL_MODELVIEW_MATRIX, store);
}
+ @Override
public FloatBuffer getProjectionMatrix(final FloatBuffer store) {
return getMatrix(GLMatrixFunc.GL_PROJECTION_MATRIX, store);
}
private FloatBuffer getMatrix(final int matrixType, final FloatBuffer store) {
FloatBuffer result = store;
- if (result.remaining() < 16) {
+ if (result == null || result.remaining() < 16) {
result = BufferUtils.createFloatBuffer(16);
}
final JoglRendererRecord matRecord = (JoglRendererRecord) ContextManager.getCurrentContext()
.getRendererRecord();
- matRecord.getMatrixBackend().getMatrix(matrixType, store);
- // GLContext.getCurrentGL().glGetFloatv(matrixType, store);
+ matRecord.getMatrixBackend().getMatrix(matrixType, result);
return result;
}
+ @Override
public void setViewport(final int x, final int y, final int width, final int height) {
GLContext.getCurrentGL().glViewport(x, y, width, height);
}
+ @Override
public void setDepthRange(final double depthRangeNear, final double depthRangeFar) {
GLContext.getCurrentGL().glDepthRange(depthRangeNear, depthRangeFar);
}
+ @Override
public void setDrawBuffer(final DrawBufferTarget target) {
final RendererRecord record = ContextManager.getCurrentContext().getRendererRecord();
if (record.getDrawBufferTarget() != target) {
@@ -1656,6 +1723,7 @@ public class JoglRenderer extends AbstractRenderer {
}
}
+ @Override
public void setupLineParameters(final float lineWidth, final int stippleFactor, final short stipplePattern,
final boolean antialiased) {
final GL gl = GLContext.getCurrentGL();
@@ -1792,14 +1860,17 @@ public class JoglRenderer extends AbstractRenderer {
throw new IllegalArgumentException("Unknown state: " + state);
}
+ @Override
public void deleteTexture(final Texture texture) {
JoglTextureStateUtil.deleteTexture(texture);
}
+ @Override
public void loadTexture(final Texture texture, final int unit) {
JoglTextureStateUtil.load(texture, unit);
}
+ @Override
public void deleteTextureIds(final Collection<Integer> ids) {
JoglTextureStateUtil.deleteTextureIds(ids);
}
@@ -1810,6 +1881,7 @@ public class JoglRenderer extends AbstractRenderer {
*
* @return id of new display list
*/
+ @Override
public int startDisplayList() {
final GL gl = GLContext.getCurrentGL();
@@ -1823,6 +1895,7 @@ public class JoglRenderer extends AbstractRenderer {
/**
* Ends a display list. Will likely cause an OpenGL exception is a display list is not currently being generated.
*/
+ @Override
public void endDisplayList() {
final GL gl = GLContext.getCurrentGL();
gl.getGL2().glEndList();
@@ -1831,12 +1904,14 @@ public class JoglRenderer extends AbstractRenderer {
/**
* Draw the given display list.
*/
+ @Override
public void renderDisplayList(final int displayListID) {
final GL gl = GLContext.getCurrentGL();
gl.getGL2().glCallList(displayListID);
}
+ @Override
public void clearClips() {
final RenderContext context = ContextManager.getCurrentContext();
final RendererRecord record = context.getRendererRecord();
@@ -1845,6 +1920,7 @@ public class JoglRenderer extends AbstractRenderer {
JoglRendererUtil.applyScissors(record);
}
+ @Override
public void popClip() {
final RenderContext context = ContextManager.getCurrentContext();
final RendererRecord record = context.getRendererRecord();
@@ -1853,6 +1929,7 @@ public class JoglRenderer extends AbstractRenderer {
JoglRendererUtil.applyScissors(record);
}
+ @Override
public void pushClip(final ReadOnlyRectangle2 rectangle) {
final RenderContext context = ContextManager.getCurrentContext();
final RendererRecord record = context.getRendererRecord();
@@ -1861,6 +1938,7 @@ public class JoglRenderer extends AbstractRenderer {
JoglRendererUtil.applyScissors(record);
}
+ @Override
public void pushEmptyClip() {
final RenderContext context = ContextManager.getCurrentContext();
final RendererRecord record = context.getRendererRecord();
@@ -1869,6 +1947,7 @@ public class JoglRenderer extends AbstractRenderer {
JoglRendererUtil.applyScissors(record);
}
+ @Override
public void setClipTestEnabled(final boolean enabled) {
final RenderContext context = ContextManager.getCurrentContext();
final RendererRecord record = context.getRendererRecord();
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglTextureRenderer.java b/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglTextureRenderer.java
index 2c68ec1..4b24580 100644
--- a/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglTextureRenderer.java
+++ b/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglTextureRenderer.java
@@ -17,6 +17,7 @@ import java.util.logging.Logger;
import javax.media.opengl.GL;
import javax.media.opengl.GL2ES2;
+import javax.media.opengl.GL2ES3;
import javax.media.opengl.GL2GL3;
import javax.media.opengl.GLContext;
@@ -41,7 +42,6 @@ import com.ardor3d.scene.state.jogl.util.JoglTextureUtil;
import com.ardor3d.scenegraph.Spatial;
import com.ardor3d.util.Ardor3dException;
import com.ardor3d.util.TextureKey;
-import com.ardor3d.util.geom.BufferUtils;
/**
* <p>
@@ -57,19 +57,13 @@ public class JoglTextureRenderer extends AbstractFBOTextureRenderer {
public JoglTextureRenderer(final int width, final int height, final int depthBits, final int samples,
final Renderer parentRenderer, final ContextCapabilities caps) {
super(width, height, depthBits, samples, parentRenderer, caps);
-
- if (caps.getMaxFBOColorAttachments() > 1) {
- _attachBuffer = BufferUtils.createIntBuffer(caps.getMaxFBOColorAttachments());
- for (int i = 0; i < caps.getMaxFBOColorAttachments(); i++) {
- _attachBuffer.put(GL.GL_COLOR_ATTACHMENT0 + i);
- }
- }
}
/**
* <code>setupTexture</code> initializes a new Texture object for use with TextureRenderer. Generates a valid OpenGL
* texture id for this texture and initializes the data type for the texture.
*/
+ @Override
public void setupTexture(final Texture tex) {
if (tex.getType() != Type.TwoDimensional && tex.getType() != Type.CubeMap) {
throw new IllegalArgumentException("Texture type not supported: " + tex.getType());
@@ -77,7 +71,7 @@ public class JoglTextureRenderer extends AbstractFBOTextureRenderer {
final GL gl = GLContext.getCurrentGL();
- final RenderContext context = ContextManager.getCurrentContext();
+ final JoglRenderContext context = (JoglRenderContext) ContextManager.getCurrentContext();
final TextureStateRecord record = (TextureStateRecord) context.getStateRecord(RenderState.StateType.Texture);
// check if we are already setup... if so, throw error.
@@ -88,7 +82,8 @@ public class JoglTextureRenderer extends AbstractFBOTextureRenderer {
}
// Create the texture
- final IntBuffer ibuf = BufferUtils.createIntBuffer(1);
+ final IntBuffer ibuf = context.getDirectNioBuffersSet().getSingleIntBuffer();
+ ibuf.clear();
gl.glGenTextures(ibuf.limit(), ibuf); // TODO Check <size>
final int textureId = ibuf.get(0);
tex.setTextureIdForContext(context.getGlContextRep(), textureId);
@@ -122,10 +117,12 @@ public class JoglTextureRenderer extends AbstractFBOTextureRenderer {
logger.fine("setup fbo tex with id " + textureId + ": " + _width + "," + _height);
}
+ @Override
public void render(final Spatial spat, final List<Texture> texs, final int clear) {
render(null, spat, null, texs, clear);
}
+ @Override
public void render(final List<? extends Spatial> spat, final List<Texture> texs, final int clear) {
render(spat, null, null, texs, clear);
}
@@ -326,8 +323,22 @@ public class JoglTextureRenderer extends AbstractFBOTextureRenderer {
if (maxEntry <= 1) {
setDrawBuffer(maxEntry != 0 ? GL.GL_COLOR_ATTACHMENT0 : GL.GL_NONE);
} else {
+ // We should only get to this point if maxDrawBuffers > 1
+ if (_attachBuffer == null) {
+ final JoglRenderContext context = (JoglRenderContext) ContextManager.getCurrentContext();
+ final ContextCapabilities caps = context.getCapabilities();
+ _attachBuffer = context.getDirectNioBuffersSet().getFboColorAttachmentBuffer();
+ _attachBuffer.rewind();
+ final int maxDrawBuffers = caps.getMaxFBOColorAttachments();
+ _attachBuffer.limit(maxDrawBuffers);
+ for (int i = 0; i < maxDrawBuffers; i++) {
+ _attachBuffer.put(GL.GL_COLOR_ATTACHMENT0 + i);
+ }
+ _attachBuffer.rewind();
+ }
+
// We should only get to this point if we support ARBDrawBuffers.
- _attachBuffer.clear();
+ _attachBuffer.rewind();
_attachBuffer.limit(maxEntry);
gl.getGL2GL3().glDrawBuffers(_attachBuffer.limit(), _attachBuffer); // TODO Check <size>
}
@@ -348,20 +359,20 @@ public class JoglTextureRenderer extends AbstractFBOTextureRenderer {
protected void setMSFBO() {
final GL gl = GLContext.getCurrentGL();
- gl.glBindFramebuffer(GL2GL3.GL_DRAW_FRAMEBUFFER, _msfboID);
+ gl.glBindFramebuffer(GL2ES3.GL_DRAW_FRAMEBUFFER, _msfboID);
}
@Override
protected void blitMSFBO() {
final GL gl = GLContext.getCurrentGL();
- gl.glBindFramebuffer(GL2GL3.GL_READ_FRAMEBUFFER, _msfboID);
- gl.glBindFramebuffer(GL2GL3.GL_DRAW_FRAMEBUFFER, _fboID);
+ gl.glBindFramebuffer(GL2ES3.GL_READ_FRAMEBUFFER, _msfboID);
+ gl.glBindFramebuffer(GL2ES3.GL_DRAW_FRAMEBUFFER, _fboID);
gl.getGL2GL3().glBlitFramebuffer(0, 0, _width, _height, 0, 0, _width, _height,
GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT, GL.GL_NEAREST);
- gl.glBindFramebuffer(GL2GL3.GL_READ_FRAMEBUFFER, 0);
- gl.glBindFramebuffer(GL2GL3.GL_DRAW_FRAMEBUFFER, 0);
+ gl.glBindFramebuffer(GL2ES3.GL_READ_FRAMEBUFFER, 0);
+ gl.glBindFramebuffer(GL2ES3.GL_DRAW_FRAMEBUFFER, 0);
gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, 0);
}
@@ -399,7 +410,7 @@ public class JoglTextureRenderer extends AbstractFBOTextureRenderer {
case GL.GL_FRAMEBUFFER_UNSUPPORTED:
throw new IllegalStateException("FrameBuffer: " + fboID
+ ", has caused a GL_FRAMEBUFFER_UNSUPPORTED_EXT exception");
- case GL2GL3.GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
+ case GL2ES3.GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
throw new IllegalStateException("FrameBuffer: " + fboID
+ ", has caused a GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT exception.");
default:
@@ -407,6 +418,7 @@ public class JoglTextureRenderer extends AbstractFBOTextureRenderer {
}
}
+ @Override
public void copyToTexture(final Texture tex, final int x, final int y, final int width, final int height,
final int xoffset, final int yoffset) {
final GL gl = GLContext.getCurrentGL();
@@ -437,7 +449,9 @@ public class JoglTextureRenderer extends AbstractFBOTextureRenderer {
// Lazy init
if (_fboID == 0) {
- final IntBuffer buffer = BufferUtils.createIntBuffer(1);
+ final JoglRenderContext context = (JoglRenderContext) ContextManager.getCurrentContext();
+ final IntBuffer buffer = context.getDirectNioBuffersSet().getSingleIntBuffer();
+ buffer.clear();
// Create our texture binding FBO
gl.glGenFramebuffers(1, buffer); // generate id
@@ -547,18 +561,23 @@ public class JoglTextureRenderer extends AbstractFBOTextureRenderer {
_active--;
}
+ @Override
public void cleanup() {
final GL gl = GLContext.getCurrentGL();
if (_fboID != 0) {
- final IntBuffer id = BufferUtils.createIntBuffer(1);
+ final JoglRenderContext context = (JoglRenderContext) ContextManager.getCurrentContext();
+ final IntBuffer id = context.getDirectNioBuffersSet().getSingleIntBuffer();
+ id.clear();
id.put(_fboID);
id.rewind();
gl.glDeleteFramebuffers(id.limit(), id);
}
if (_depthRBID != 0) {
- final IntBuffer id = BufferUtils.createIntBuffer(1);
+ final JoglRenderContext context = (JoglRenderContext) ContextManager.getCurrentContext();
+ final IntBuffer id = context.getDirectNioBuffersSet().getSingleIntBuffer();
+ id.clear();
id.put(_depthRBID);
id.rewind();
gl.glDeleteRenderbuffers(id.limit(), id);
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglTextureRendererProvider.java b/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglTextureRendererProvider.java
index a93e0cf..57117f8 100644
--- a/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglTextureRendererProvider.java
+++ b/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglTextureRendererProvider.java
@@ -22,21 +22,24 @@ public class JoglTextureRendererProvider implements TextureRendererProvider {
private static final Logger logger = Logger.getLogger(JoglTextureRendererProvider.class.getName());
+ @Override
public TextureRenderer createTextureRenderer(final int width, final int height, final Renderer renderer,
final ContextCapabilities caps) {
return createTextureRenderer(width, height, 0, 0, renderer, caps);
}
+ @Override
public TextureRenderer createTextureRenderer(final int width, final int height, final int depthBits,
final int samples, final Renderer renderer, final ContextCapabilities caps) {
return createTextureRenderer(new DisplaySettings(width, height, depthBits, samples), false, renderer, caps);
}
+ @Override
public TextureRenderer createTextureRenderer(final DisplaySettings settings, final boolean forcePbuffer,
final Renderer renderer, final ContextCapabilities caps) {
if (!forcePbuffer && caps.isFBOSupported()) {
- return new JoglTextureRenderer(settings.getWidth(), settings.getHeight(), settings.getDepthBits(), settings
- .getSamples(), renderer, caps);
+ return new JoglTextureRenderer(settings.getWidth(), settings.getHeight(), settings.getDepthBits(),
+ settings.getSamples(), renderer, caps);
} else if (caps.isPbufferSupported()) {
return new JoglPbufferTextureRenderer(settings, renderer, caps);
} else {
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglFragmentProgramStateUtil.java b/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglFragmentProgramStateUtil.java
index f71e4f5..b227ae4 100644
--- a/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglFragmentProgramStateUtil.java
+++ b/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglFragmentProgramStateUtil.java
@@ -21,11 +21,11 @@ import javax.media.opengl.GLContext;
import com.ardor3d.renderer.ContextCapabilities;
import com.ardor3d.renderer.ContextManager;
import com.ardor3d.renderer.RenderContext;
+import com.ardor3d.renderer.jogl.JoglRenderContext;
import com.ardor3d.renderer.jogl.JoglRenderer;
import com.ardor3d.renderer.state.FragmentProgramState;
import com.ardor3d.renderer.state.RenderState.StateType;
import com.ardor3d.renderer.state.record.FragmentProgramStateRecord;
-import com.ardor3d.util.geom.BufferUtils;
public final class JoglFragmentProgramStateUtil {
private static final Logger logger = Logger.getLogger(JoglFragmentProgramStateUtil.class.getName());
@@ -39,7 +39,9 @@ public final class JoglFragmentProgramStateUtil {
if (gl.glGetError() == GL.GL_INVALID_OPERATION) {
// retrieve the error position
- final IntBuffer errorloc = BufferUtils.createIntBuffer(16);
+ final JoglRenderContext context = (JoglRenderContext) ContextManager.getCurrentContext();
+ final IntBuffer errorloc = context.getDirectNioBuffersSet().getSingleIntBuffer();
+ errorloc.clear();
gl.glGetIntegerv(GL2.GL_PROGRAM_ERROR_POSITION_ARB, errorloc); // TODO Check for integer
logger.severe("Error " + gl.glGetString(GL2.GL_PROGRAM_ERROR_STRING_ARB) + " in fragment program on line "
@@ -50,7 +52,9 @@ public final class JoglFragmentProgramStateUtil {
private static int create(final ByteBuffer program) {
final GL gl = GLContext.getCurrentGL();
- final IntBuffer buf = BufferUtils.createIntBuffer(1);
+ final JoglRenderContext context = (JoglRenderContext) ContextManager.getCurrentContext();
+ final IntBuffer buf = context.getDirectNioBuffersSet().getSingleIntBuffer();
+ buf.clear();
gl.getGL2().glGenProgramsARB(buf.limit(), buf); // TODO Check <size>
gl.getGL2().glBindProgramARB(GL2.GL_FRAGMENT_PROGRAM_ARB, buf.get(0));
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglShaderObjectsStateUtil.java b/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglShaderObjectsStateUtil.java
index c28b028..ebb53a8 100644
--- a/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglShaderObjectsStateUtil.java
+++ b/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglShaderObjectsStateUtil.java
@@ -25,6 +25,7 @@ import javax.media.opengl.GLContext;
import com.ardor3d.renderer.ContextCapabilities;
import com.ardor3d.renderer.ContextManager;
import com.ardor3d.renderer.RenderContext;
+import com.ardor3d.renderer.jogl.JoglRenderContext;
import com.ardor3d.renderer.jogl.JoglRenderer;
import com.ardor3d.renderer.state.GLSLShaderObjectsState;
import com.ardor3d.renderer.state.RenderState.StateType;
@@ -83,7 +84,9 @@ public abstract class JoglShaderObjectsStateUtil {
}
// Compile the vertex shader
- final IntBuffer compiled = BufferUtils.createIntBuffer(1);
+ final JoglRenderContext context = (JoglRenderContext) ContextManager.getCurrentContext();
+ final IntBuffer compiled = context.getDirectNioBuffersSet().getSingleIntBuffer();
+ compiled.clear();
if (gl.isGL2()) {
gl.getGL2().glCompileShaderARB(state._vertexShaderID);
gl.getGL2()
@@ -94,7 +97,7 @@ public abstract class JoglShaderObjectsStateUtil {
gl.getGL2ES2().glGetShaderiv(state._vertexShaderID, GL2ES2.GL_COMPILE_STATUS, compiled);
}
}
- checkProgramError(compiled, state._vertexShaderID, state._vertexShaderName);
+ checkProgramError(compiled.get(0), state._vertexShaderID, state._vertexShaderName);
// Attach the program
if (gl.isGL2()) {
@@ -137,7 +140,9 @@ public abstract class JoglShaderObjectsStateUtil {
}
// Compile the fragment shader
- final IntBuffer compiled = BufferUtils.createIntBuffer(1);
+ final JoglRenderContext context = (JoglRenderContext) ContextManager.getCurrentContext();
+ final IntBuffer compiled = context.getDirectNioBuffersSet().getSingleIntBuffer();
+ compiled.clear();
if (gl.isGL2()) {
gl.getGL2().glCompileShaderARB(state._fragmentShaderID);
gl.getGL2().glGetObjectParameterivARB(state._fragmentShaderID, GL2.GL_OBJECT_COMPILE_STATUS_ARB,
@@ -148,7 +153,7 @@ public abstract class JoglShaderObjectsStateUtil {
gl.getGL2ES2().glGetShaderiv(state._fragmentShaderID, GL2ES2.GL_COMPILE_STATUS, compiled);
}
}
- checkProgramError(compiled, state._fragmentShaderID, state._vertexShaderName);
+ checkProgramError(compiled.get(0), state._fragmentShaderID, state._vertexShaderName);
// Attach the program
if (gl.isGL2()) {
@@ -192,7 +197,9 @@ public abstract class JoglShaderObjectsStateUtil {
}
// Compile the geometry shader
- final IntBuffer compiled = BufferUtils.createIntBuffer(1);
+ final JoglRenderContext context = (JoglRenderContext) ContextManager.getCurrentContext();
+ final IntBuffer compiled = context.getDirectNioBuffersSet().getSingleIntBuffer();
+ compiled.clear();
if (gl.isGL2()) {
gl.getGL2().glCompileShaderARB(state._geometryShaderID);
gl.getGL2().glGetObjectParameterivARB(state._geometryShaderID, GL2.GL_OBJECT_COMPILE_STATUS_ARB,
@@ -203,7 +210,7 @@ public abstract class JoglShaderObjectsStateUtil {
gl.getGL2ES2().glGetShaderiv(state._geometryShaderID, GL2ES2.GL_COMPILE_STATUS, compiled);
}
}
- checkProgramError(compiled, state._geometryShaderID, state._geometryShaderName);
+ checkProgramError(compiled.get(0), state._geometryShaderID, state._geometryShaderName);
// Attach the program
if (gl.isGL2()) {
@@ -249,7 +256,9 @@ public abstract class JoglShaderObjectsStateUtil {
}
// Compile the tessellation control shader
- final IntBuffer compiled = BufferUtils.createIntBuffer(1);
+ final JoglRenderContext context = (JoglRenderContext) ContextManager.getCurrentContext();
+ final IntBuffer compiled = context.getDirectNioBuffersSet().getSingleIntBuffer();
+ compiled.clear();
if (gl.isGL2()) {
gl.getGL2().glCompileShaderARB(state._tessellationControlShaderID);
gl.getGL2().glGetObjectParameterivARB(state._tessellationControlShaderID,
@@ -261,7 +270,8 @@ public abstract class JoglShaderObjectsStateUtil {
compiled);
}
}
- checkProgramError(compiled, state._tessellationControlShaderID, state._tessellationControlShaderName);
+ checkProgramError(compiled.get(0), state._tessellationControlShaderID,
+ state._tessellationControlShaderName);
// Attach the program
if (gl.isGL2()) {
@@ -305,7 +315,9 @@ public abstract class JoglShaderObjectsStateUtil {
}
// Compile the tessellation control shader
- final IntBuffer compiled = BufferUtils.createIntBuffer(1);
+ final JoglRenderContext context = (JoglRenderContext) ContextManager.getCurrentContext();
+ final IntBuffer compiled = context.getDirectNioBuffersSet().getSingleIntBuffer();
+ compiled.clear();
if (gl.isGL2()) {
gl.getGL2().glCompileShaderARB(state._tessellationEvaluationShaderID);
gl.getGL2().glGetObjectParameterivARB(state._tessellationEvaluationShaderID,
@@ -317,7 +329,7 @@ public abstract class JoglShaderObjectsStateUtil {
compiled);
}
}
- checkProgramError(compiled, state._tessellationEvaluationShaderID,
+ checkProgramError(compiled.get(0), state._tessellationEvaluationShaderID,
state._tessellationEvaluationShaderName);
// Attach the program
@@ -349,7 +361,9 @@ public abstract class JoglShaderObjectsStateUtil {
private static void checkLinkError(final int programId) {
final GL gl = GLContext.getCurrentGL();
- final IntBuffer compiled = BufferUtils.createIntBuffer(1);
+ final JoglRenderContext context = (JoglRenderContext) ContextManager.getCurrentContext();
+ final IntBuffer compiled = context.getDirectNioBuffersSet().getSingleIntBuffer();
+ compiled.clear();
if (gl.isGL2()) {
gl.getGL2().glGetObjectParameterivARB(programId, GL2ES2.GL_LINK_STATUS, compiled);
} else {
@@ -368,12 +382,19 @@ public abstract class JoglShaderObjectsStateUtil {
final int length = compiled.get(0);
String out = null;
if (length > 0) {
- final ByteBuffer infoLog = BufferUtils.createByteBuffer(length);
+ final ByteBuffer infoLogBuf = context.getDirectNioBuffersSet().getInfoLogBuffer();
+ final ByteBuffer infoLog;
+ if (length <= infoLogBuf.capacity()) {
+ infoLog = infoLogBuf;
+ infoLogBuf.rewind().limit(length);
+ } else {
+ infoLog = BufferUtils.createByteBuffer(length);
+ }
if (gl.isGL2()) {
gl.getGL2().glGetInfoLogARB(programId, infoLog.limit(), compiled, infoLog);
} else {
if (gl.isGL2ES2()) {
- gl.getGL2ES2().glGetProgramInfoLog(programId, length, null, infoLog);
+ gl.getGL2ES2().glGetProgramInfoLog(programId, infoLog.limit(), compiled, infoLog);
}
}
@@ -476,33 +497,42 @@ public abstract class JoglShaderObjectsStateUtil {
/**
* Check for program errors. If an error is detected, program exits.
*
- * @param compiled
+ * @param compilerState
* the compiler state for a given shader
* @param id
* shader's id
*/
- private static void checkProgramError(final IntBuffer compiled, final int id, final String shaderName) {
+ private static void checkProgramError(final int compilerState, final int id, final String shaderName) {
final GL gl = GLContext.getCurrentGL();
- if (compiled.get(0) == GL.GL_FALSE) {
- final IntBuffer iVal = BufferUtils.createIntBuffer(1);
+ if (compilerState == GL.GL_FALSE) {
+ final JoglRenderContext context = (JoglRenderContext) ContextManager.getCurrentContext();
+ final IntBuffer iVal = context.getDirectNioBuffersSet().getSingleIntBuffer();
+ iVal.clear();
if (gl.isGL2()) {
gl.getGL2().glGetObjectParameterivARB(id, GL2.GL_OBJECT_INFO_LOG_LENGTH_ARB, iVal);
} else {
if (gl.isGL2ES2()) {
- gl.getGL2ES2().glGetProgramiv(id, GL2ES2.GL_INFO_LOG_LENGTH, compiled);
+ gl.getGL2ES2().glGetProgramiv(id, GL2ES2.GL_INFO_LOG_LENGTH, iVal);
}
}
final int length = iVal.get(0);
String out = null;
if (length > 0) {
- final ByteBuffer infoLog = BufferUtils.createByteBuffer(length);
+ final ByteBuffer infoLogBuf = context.getDirectNioBuffersSet().getInfoLogBuffer();
+ final ByteBuffer infoLog;
+ if (length <= infoLogBuf.capacity()) {
+ infoLog = infoLogBuf;
+ infoLogBuf.rewind().limit(length);
+ } else {
+ infoLog = BufferUtils.createByteBuffer(length);
+ }
if (gl.isGL2()) {
gl.getGL2().glGetInfoLogARB(id, infoLog.limit(), iVal, infoLog);
} else {
if (gl.isGL2ES2()) {
- gl.getGL2ES2().glGetProgramInfoLog(id, length, null, infoLog);
+ gl.getGL2ES2().glGetProgramInfoLog(id, infoLog.limit(), iVal, infoLog);
}
}
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglTextureStateUtil.java b/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglTextureStateUtil.java
index 7e8adc0..63031ab 100644
--- a/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglTextureStateUtil.java
+++ b/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglTextureStateUtil.java
@@ -19,6 +19,7 @@ import javax.media.opengl.GL;
import javax.media.opengl.GL2;
import javax.media.opengl.GL2ES1;
import javax.media.opengl.GL2ES2;
+import javax.media.opengl.GL2ES3;
import javax.media.opengl.GL2GL3;
import javax.media.opengl.GLContext;
import javax.media.opengl.GLDrawable;
@@ -47,6 +48,7 @@ import com.ardor3d.math.type.ReadOnlyColorRGBA;
import com.ardor3d.renderer.ContextCapabilities;
import com.ardor3d.renderer.ContextManager;
import com.ardor3d.renderer.RenderContext;
+import com.ardor3d.renderer.jogl.JoglRenderContext;
import com.ardor3d.renderer.jogl.JoglRenderer;
import com.ardor3d.renderer.jogl.state.record.JoglRendererRecord;
import com.ardor3d.renderer.state.RenderState.StateType;
@@ -72,7 +74,7 @@ public class JoglTextureStateUtil {
}
final GL gl = GLContext.getCurrentGL();
- final RenderContext context = ContextManager.getCurrentContext();
+ final JoglRenderContext context = (JoglRenderContext) ContextManager.getCurrentContext();
if (context == null) {
logger.warning("RenderContext is null for texture: " + texture);
return;
@@ -104,7 +106,7 @@ public class JoglTextureStateUtil {
}
}
- final IntBuffer id = BufferUtils.createIntBuffer(1);
+ final IntBuffer id = context.getDirectNioBuffersSet().getSingleIntBuffer();
id.clear();
gl.glGenTextures(id.limit(), id);
final int textureId = id.get(0);
@@ -420,7 +422,7 @@ public class JoglTextureStateUtil {
}
if (texture.getTextureMaxLevel() >= 0) {
- gl.glTexParameteri(GL.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_MAX_LEVEL, texture.getTextureMaxLevel());
+ gl.glTexParameteri(GL.GL_TEXTURE_2D, GL2ES3.GL_TEXTURE_MAX_LEVEL, texture.getTextureMaxLevel());
}
} else {
// Here we handle textures that are either compressed or have predefined mipmaps.
@@ -436,20 +438,22 @@ public class JoglTextureStateUtil {
int max = 1;
if (mipSizes == null) {
- mipSizes = new int[] { data.capacity() };
+ mipSizes = new int[] { data == null ? 0 : data.capacity() };
} else if (texture.getMinificationFilter().usesMipMapLevels()) {
max = mipSizes.length;
}
// set max mip level
- gl.glTexParameteri(getGLCubeMapFace(face), GL2GL3.GL_TEXTURE_MAX_LEVEL, max - 1);
+ gl.glTexParameteri(getGLCubeMapFace(face), GL2ES3.GL_TEXTURE_MAX_LEVEL, max - 1);
for (int m = 0; m < max; m++) {
final int width = Math.max(1, image.getWidth() >> m);
final int height = Math.max(1, image.getHeight() >> m);
- data.position(pos);
- data.limit(pos + mipSizes[m]);
+ if (data != null) {
+ data.position(pos);
+ data.limit(pos + mipSizes[m]);
+ }
if (texture.getTextureStoreFormat().isCompressed()) {
gl.glCompressedTexImage2D(getGLCubeMapFace(face), m,
@@ -483,13 +487,13 @@ public class JoglTextureStateUtil {
// Set max mip level
switch (type) {
case TwoDimensional:
- gl.glTexParameteri(GL.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_MAX_LEVEL, max - 1);
+ gl.glTexParameteri(GL.GL_TEXTURE_2D, GL2ES3.GL_TEXTURE_MAX_LEVEL, max - 1);
break;
case ThreeDimensional:
- gl.glTexParameteri(GL2ES2.GL_TEXTURE_3D, GL2GL3.GL_TEXTURE_MAX_LEVEL, max - 1);
+ gl.glTexParameteri(GL2ES2.GL_TEXTURE_3D, GL2ES3.GL_TEXTURE_MAX_LEVEL, max - 1);
break;
case OneDimensional:
- gl.glTexParameteri(GL2GL3.GL_TEXTURE_1D, GL2GL3.GL_TEXTURE_MAX_LEVEL, max - 1);
+ gl.glTexParameteri(GL2GL3.GL_TEXTURE_1D, GL2ES3.GL_TEXTURE_MAX_LEVEL, max - 1);
break;
case CubeMap:
break;
@@ -1617,7 +1621,7 @@ public class JoglTextureStateUtil {
final GL gl = GLContext.getCurrentGL();
// ask for the current state record
- final RenderContext context = ContextManager.getCurrentContext();
+ final JoglRenderContext context = (JoglRenderContext) ContextManager.getCurrentContext();
final TextureStateRecord record = (TextureStateRecord) context.getStateRecord(StateType.Texture);
final Integer id = texture.getTextureIdForContextAsInteger(context.getGlContextRep());
@@ -1626,7 +1630,7 @@ public class JoglTextureStateUtil {
return;
}
- final IntBuffer idBuffer = BufferUtils.createIntBuffer(1);
+ final IntBuffer idBuffer = context.getDirectNioBuffersSet().getSingleIntBuffer();
idBuffer.clear();
idBuffer.put(id.intValue());
idBuffer.rewind();
@@ -1639,21 +1643,29 @@ public class JoglTextureStateUtil {
final GL gl = GLContext.getCurrentGL();
// ask for the current state record
- final RenderContext context = ContextManager.getCurrentContext();
+ final JoglRenderContext context = (JoglRenderContext) ContextManager.getCurrentContext();
final TextureStateRecord record = (TextureStateRecord) context.getStateRecord(StateType.Texture);
- final IntBuffer idBuffer = BufferUtils.createIntBuffer(ids.size());
- idBuffer.clear();
+ final IntBuffer texIdsBuffer = context.getDirectNioBuffersSet().getTextureIdsBuffer();
+ texIdsBuffer.clear();
for (final Integer i : ids) {
+ if (!texIdsBuffer.hasRemaining()) {
+ texIdsBuffer.flip();
+ if (texIdsBuffer.remaining() > 0) {
+ gl.glDeleteTextures(texIdsBuffer.remaining(), texIdsBuffer);
+ }
+ texIdsBuffer.clear();
+ }
if (i != null) {
- idBuffer.put(i);
+ texIdsBuffer.put(i);
record.removeTextureRecord(i);
}
}
- idBuffer.flip();
- if (idBuffer.remaining() > 0) {
- gl.glDeleteTextures(idBuffer.remaining(), idBuffer);
+ texIdsBuffer.flip();
+ if (texIdsBuffer.remaining() > 0) {
+ gl.glDeleteTextures(texIdsBuffer.remaining(), texIdsBuffer);
}
+ texIdsBuffer.clear();
}
/**
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglVertexProgramStateUtil.java b/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglVertexProgramStateUtil.java
index 3cf3149..727d7ec 100644
--- a/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglVertexProgramStateUtil.java
+++ b/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglVertexProgramStateUtil.java
@@ -21,11 +21,11 @@ import javax.media.opengl.GLContext;
import com.ardor3d.renderer.ContextCapabilities;
import com.ardor3d.renderer.ContextManager;
import com.ardor3d.renderer.RenderContext;
+import com.ardor3d.renderer.jogl.JoglRenderContext;
import com.ardor3d.renderer.jogl.JoglRenderer;
import com.ardor3d.renderer.state.RenderState.StateType;
import com.ardor3d.renderer.state.VertexProgramState;
import com.ardor3d.renderer.state.record.VertexProgramStateRecord;
-import com.ardor3d.util.geom.BufferUtils;
public abstract class JoglVertexProgramStateUtil {
private static final Logger logger = Logger.getLogger(JoglVertexProgramStateUtil.class.getName());
@@ -39,7 +39,9 @@ public abstract class JoglVertexProgramStateUtil {
if (gl.glGetError() == GL.GL_INVALID_OPERATION) {
// retrieve the error position
- final IntBuffer errorloc = BufferUtils.createIntBuffer(16);
+ final JoglRenderContext context = (JoglRenderContext) ContextManager.getCurrentContext();
+ final IntBuffer errorloc = context.getDirectNioBuffersSet().getSingleIntBuffer();
+ errorloc.clear();
gl.glGetIntegerv(GL2.GL_PROGRAM_ERROR_POSITION_ARB, errorloc); // TODO Check for integer
logger.severe("Error " + gl.glGetString(GL2.GL_PROGRAM_ERROR_STRING_ARB) + " in vertex program on line "
@@ -50,7 +52,9 @@ public abstract class JoglVertexProgramStateUtil {
private static int create(final ByteBuffer program) {
final GL gl = GLContext.getCurrentGL();
- final IntBuffer buf = BufferUtils.createIntBuffer(1);
+ final JoglRenderContext context = (JoglRenderContext) ContextManager.getCurrentContext();
+ final IntBuffer buf = context.getDirectNioBuffersSet().getSingleIntBuffer();
+ buf.clear();
gl.getGL2().glGenProgramsARB(buf.limit(), buf);
gl.getGL2().glBindProgramARB(GL2.GL_VERTEX_PROGRAM_ARB, buf.get(0));