aboutsummaryrefslogtreecommitdiffstats
path: root/ardor3d-jogl
diff options
context:
space:
mode:
Diffstat (limited to 'ardor3d-jogl')
-rw-r--r--ardor3d-jogl/pom.xml9
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglAwtCanvas.java14
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglCanvas.java10
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglCanvasRenderer.java46
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglInitializerRunnable.java15
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglLibraryPaths.java59
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglNewtAwtCanvas.java54
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglNewtWindow.java74
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/image/util/jogl/JoglImageLoader.java128
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/input/jogl/JoglNewtKey.java17
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglPbufferTextureRenderer.java3
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglRenderContext.java37
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglRenderer.java329
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/state/record/JoglMatrixBackend.java32
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/state/record/JoglRealMatrixBackend.java77
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/state/record/JoglRendererRecord.java34
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/state/record/JoglSimulatedMatrixBackend.java68
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglBlendStateUtil.java30
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglClipStateUtil.java13
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglShaderObjectsStateUtil.java333
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglTextureStateUtil.java15
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/shader/JoglShaderUtil.java77
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/util/JoglRendererUtil.java7
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/util/JoglTextureUtil.java65
24 files changed, 1191 insertions, 355 deletions
diff --git a/ardor3d-jogl/pom.xml b/ardor3d-jogl/pom.xml
index 74b1a4d..68116fb 100644
--- a/ardor3d-jogl/pom.xml
+++ b/ardor3d-jogl/pom.xml
@@ -48,5 +48,10 @@
<version>2.0-rc11</version>
</dependency> -->
</dependencies>
-</project>
-
+ <repositories>
+ <repository>
+ <id>jogamp</id>
+ <url>http://jogamp.org/deployment/maven</url>
+ </repository>
+ </repositories>
+</project> \ No newline at end of file
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 58fef71..6e3d140 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
@@ -13,6 +13,8 @@ package com.ardor3d.framework.jogl;
import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.CountDownLatch;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLRunnable;
import javax.media.opengl.awt.GLCanvas;
import javax.swing.SwingUtilities;
@@ -71,7 +73,7 @@ public class JoglAwtCanvas extends GLCanvas implements Canvas {
_initializerRunnable.run();
}
- _inited = true;
+ _inited = isRealized();
}
public void draw(final CountDownLatch latch) {
@@ -90,4 +92,14 @@ public class JoglAwtCanvas extends GLCanvas implements Canvas {
public JoglCanvasRenderer getCanvasRenderer() {
return _canvasRenderer;
}
+
+ public void setVSyncEnabled(final boolean enabled) {
+ invoke(true, new GLRunnable() {
+ @Override
+ public boolean run(final GLAutoDrawable glAutoDrawable) {
+ glAutoDrawable.getGL().setSwapInterval(enabled ? 1 : 0);
+ return false;
+ }
+ });
+ }
}
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 c08396b..def1f49 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
@@ -27,10 +27,8 @@ import java.util.concurrent.CountDownLatch;
import java.util.logging.Level;
import java.util.logging.Logger;
-import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLContext;
import javax.media.opengl.GLException;
-import javax.media.opengl.GLRunnable;
import com.ardor3d.annotation.MainThread;
import com.ardor3d.framework.CanvasRenderer;
@@ -274,12 +272,6 @@ public class JoglCanvas extends Frame implements NativeCanvas {
}
public void setVSyncEnabled(final boolean enabled) {
- _glCanvas.invoke(true, new GLRunnable() {
- @Override
- public boolean run(GLAutoDrawable glAutoDrawable) {
- _glCanvas.getGL().setSwapInterval(enabled ? 1 : 0);
- return false;
- }
- });
+ _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 d77edb0..22fa92e 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
@@ -13,6 +13,12 @@ package com.ardor3d.framework.jogl;
import java.util.logging.Logger;
import javax.media.opengl.DebugGL2;
+import javax.media.opengl.DebugGL3;
+import javax.media.opengl.DebugGL3bc;
+import javax.media.opengl.DebugGL4;
+import javax.media.opengl.DebugGL4bc;
+import javax.media.opengl.DebugGLES1;
+import javax.media.opengl.DebugGLES2;
import javax.media.opengl.GL;
import javax.media.opengl.GLContext;
import javax.media.opengl.GLDrawableFactory;
@@ -32,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;
@@ -46,7 +53,7 @@ public class JoglCanvasRenderer implements CanvasRenderer {
protected JoglRenderer _renderer;
protected int _frameClear = Renderer.BUFFER_COLOR_AND_DEPTH;
- private RenderContext _currentContext;
+ private JoglRenderContext _currentContext;
/**
* <code>true</code> if debugging (checking for error codes on each GL call) is desired.
@@ -137,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);
@@ -193,7 +200,37 @@ public class JoglCanvasRenderer implements CanvasRenderer {
// Enable Debugging if requested.
if (_useDebug != _debugEnabled) {
- _context.setGL(new DebugGL2(_context.getGL().getGL2()));
+ if (_context.getGL().isGLES()) {
+ if (_context.getGL().isGLES1()) {
+ _context.setGL(new DebugGLES1(_context.getGL().getGLES1()));
+ } else {
+ if (_context.getGL().isGLES2()) {
+ _context.setGL(new DebugGLES2(_context.getGL().getGLES2()));
+ } else {
+ // TODO ES3
+ }
+ }
+ } else {
+ if (_context.getGL().isGL4bc()) {
+ _context.setGL(new DebugGL4bc(_context.getGL().getGL4bc()));
+ } else {
+ if (_context.getGL().isGL4()) {
+ _context.setGL(new DebugGL4(_context.getGL().getGL4()));
+ } else {
+ if (_context.getGL().isGL3bc()) {
+ _context.setGL(new DebugGL3bc(_context.getGL().getGL3bc()));
+ } else {
+ if (_context.getGL().isGL3()) {
+ _context.setGL(new DebugGL3(_context.getGL().getGL3()));
+ } else {
+ if (_context.getGL().isGL2()) {
+ _context.setGL(new DebugGL2(_context.getGL().getGL2()));
+ }
+ }
+ }
+ }
+ }
+ }
_debugEnabled = true;
LOGGER.info("DebugGL Enabled");
@@ -239,7 +276,8 @@ public class JoglCanvasRenderer implements CanvasRenderer {
_camera = camera;
}
- public RenderContext getRenderContext() {
+ @Override
+ public JoglRenderContext getRenderContext() {
return _currentContext;
}
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglInitializerRunnable.java b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglInitializerRunnable.java
index 2a93f38..8e621f7 100644
--- a/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglInitializerRunnable.java
+++ b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglInitializerRunnable.java
@@ -29,14 +29,13 @@ public class JoglInitializerRunnable implements Runnable {
_joglAwtCanvas.setVisible(true);
// Force the realization
_joglAwtCanvas.display();
- if (!_joglAwtCanvas.getDelegatedDrawable().isRealized()) {
- throw new RuntimeException("The heavyweight AWT drawable cannot be realized");
+ if (_joglAwtCanvas.getDelegatedDrawable().isRealized()) {
+ // Request the focus here as it cannot work when the window is not visible
+ _joglAwtCanvas.requestFocus();
+ // The OpenGL context has been created after the realization of the surface
+ _joglAwtCanvas.getCanvasRenderer().setContext(_joglAwtCanvas.getContext());
+ // As the canvas renderer knows the OpenGL context, it can be initialized
+ _joglAwtCanvas.getCanvasRenderer().init(_settings, true);
}
- // Request the focus here as it cannot work when the window is not visible
- _joglAwtCanvas.requestFocus();
- // The OpenGL context has been created after the realization of the surface
- _joglAwtCanvas.getCanvasRenderer().setContext(_joglAwtCanvas.getContext());
- // As the canvas renderer knows the OpenGL context, it can be initialized
- _joglAwtCanvas.getCanvasRenderer().init(_settings, true);
}
} \ No newline at end of file
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglLibraryPaths.java b/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglLibraryPaths.java
deleted file mode 100644
index 668e74e..0000000
--- a/ardor3d-jogl/src/main/java/com/ardor3d/framework/jogl/JoglLibraryPaths.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/**
- * 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 <http://www.ardor3d.com/LICENSE>.
- */
-
-package com.ardor3d.framework.jogl;
-
-/**
- * TODO: document this class!
- *
- */
-public enum JoglLibraryPaths {
- MACOSX("Mac OS X", null, new String[] {
- "/macosx/libgluegen-rt.jnilib",
- "/macosx/libjogl.jnilib",
- "/macosx/libjogl_awt.jnilib",
- "/macosx/libjogl_cg.jnilib",
- }),
- WINDOWS_XP("Windows XP", null, new String[] {
- "/win32/gluegen-rt.dll",
- "/win32/jogl.dll",
- "/win32/jogl_awt.dll",
- "/win32/jogl_cg.dll",
- });
-
- private final String _operatingSystem;
- private final String _architecture;
- private final String[] _libraryPaths;
-
-
- JoglLibraryPaths(String operatingSystem, String architecture, String[] libraryPaths) {
- _operatingSystem = operatingSystem;
- _architecture = architecture;
- _libraryPaths = libraryPaths;
- }
-
- public static String[] getLibraryPaths(String operatingSystem, String architecture) {
- for (JoglLibraryPaths libraryPath : JoglLibraryPaths.values()) {
- if (operatingSystem.equals(libraryPath._operatingSystem) &&
- (libraryPath._architecture == null || architecture.equals(libraryPath._architecture))) {
- return libraryPath._libraryPaths;
- }
- }
-
- throw new IllegalStateException("No matching set of library paths found for " + operatingSystem + ", " + architecture);
- }
-
- public static void main(String[] args) {
- System.out.println(System.getProperty("os.name"));
- System.out.println(System.getProperty("os.arch"));
-
- System.getProperties();
- }
-} \ No newline at end of file
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 8b2517a..0de1c99 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
@@ -11,15 +11,16 @@
package com.ardor3d.framework.jogl;
import java.util.concurrent.CountDownLatch;
+
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLRunnable;
+
import com.ardor3d.annotation.MainThread;
import com.ardor3d.framework.Canvas;
import com.ardor3d.framework.DisplaySettings;
import com.jogamp.newt.awt.NewtCanvasAWT;
import com.jogamp.newt.opengl.GLWindow;
-
public class JoglNewtAwtCanvas extends NewtCanvasAWT implements Canvas, NewtWindowContainer {
private static final long serialVersionUID = 1L;
@@ -28,7 +29,7 @@ public class JoglNewtAwtCanvas extends NewtCanvasAWT implements Canvas, NewtWind
private boolean _inited = false;
private final DisplaySettings _settings;
-
+
private final JoglDrawerRunnable _drawerGLRunnable;
public JoglNewtAwtCanvas(final DisplaySettings settings, final JoglCanvasRenderer canvasRenderer) {
@@ -41,7 +42,7 @@ public class JoglNewtAwtCanvas extends NewtCanvasAWT implements Canvas, NewtWind
setFocusable(true);
setSize(_settings.getWidth(), _settings.getHeight());
setIgnoreRepaint(true);
- getNewtWindow().setAutoSwapBufferMode(false);
+ getNewtWindow().setAutoSwapBufferMode(false);
}
@MainThread
@@ -49,25 +50,26 @@ public class JoglNewtAwtCanvas extends NewtCanvasAWT implements Canvas, NewtWind
if (_inited) {
return;
}
-
+
// Make the window visible to realize the OpenGL surface.
setVisible(true);
- // Request the focus here as it cannot work when the window is not visible
- requestFocus();
- /**
- * I do not understand why I cannot get the context earlier, I failed in
- * getting it from addNotify() and setVisible(true)
- * */
- _canvasRenderer.setContext(getNewtWindow().getContext());
-
- getNewtWindow().invoke(true, new GLRunnable() {
- @Override
- public boolean run(GLAutoDrawable glAutoDrawable) {
- _canvasRenderer.init(_settings, true);// true - do swap in renderer.
- return true;
- }
- });
- _inited = true;
+ if (getNewtWindow().isRealized()) {
+ // Request the focus here as it cannot work when the window is not visible
+ requestFocus();
+ /**
+ * I do not understand why I cannot get the context earlier, I failed in getting it from addNotify() and
+ * setVisible(true)
+ * */
+ _canvasRenderer.setContext(getNewtWindow().getContext());
+ getNewtWindow().invoke(true, new GLRunnable() {
+ @Override
+ public boolean run(final GLAutoDrawable glAutoDrawable) {
+ _canvasRenderer.init(_settings, true);// true - do swap in renderer.
+ return true;
+ }
+ });
+ _inited = true;
+ }
}
public void draw(final CountDownLatch latch) {
@@ -86,9 +88,19 @@ public class JoglNewtAwtCanvas extends NewtCanvasAWT implements Canvas, NewtWind
public JoglCanvasRenderer getCanvasRenderer() {
return _canvasRenderer;
}
-
+
@Override
public GLWindow getNewtWindow() {
return (GLWindow) getNEWTChild();
}
+
+ public void setVSyncEnabled(final boolean enabled) {
+ getNewtWindow().invoke(true, new GLRunnable() {
+ @Override
+ public boolean run(final GLAutoDrawable glAutoDrawable) {
+ glAutoDrawable.getGL().setSwapInterval(enabled ? 1 : 0);
+ return false;
+ }
+ });
+ }
}
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 9490dea..a7cb777 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,46 +140,48 @@ public class JoglNewtWindow implements NativeCanvas, NewtWindowContainer {
return;
}
- _newtWindow.addWindowListener(new WindowAdapter() {
- @Override
- public void windowDestroyNotify(final WindowEvent e) {
- _isClosing = true;
- }
-
- // public void windowResized(final WindowEvent e) {
- // _newtWindow.invoke(true, new GLRunnable() {
- //
- // @Override
- // public boolean run(GLAutoDrawable glAutoDrawable) {
- // _canvasRenderer._camera.resize(_newtWindow.getWidth(), _newtWindow.getHeight());
- // _canvasRenderer._camera.setFrustumPerspective(_canvasRenderer._camera.getFovY(),
- // (float) _newtWindow.getWidth() / (float) _newtWindow.getHeight(),
- // _canvasRenderer._camera.getFrustumNear(),
- // _canvasRenderer._camera.getFrustumFar());
- // return true;
- // }
- // });
- // }
- });
-
// Set the size very early to prevent the default one from being used (typically when exiting full screen mode)
setSize(_settings.getWidth(), _settings.getHeight());
// Make the window visible to realize the OpenGL surface.
setVisible(true);
- // Request the focus here as it cannot work when the window is not visible
- _newtWindow.requestFocus();
- applySettings();
-
- _canvasRenderer.setContext(getContext());
-
- _newtWindow.invoke(true, new GLRunnable() {
- @Override
- public boolean run(final GLAutoDrawable glAutoDrawable) {
- _canvasRenderer.init(_settings, true);// true - do swap in renderer.
- return true;
- }
- });
- _inited = true;
+ if (_newtWindow.isRealized()) {
+ _newtWindow.addWindowListener(new WindowAdapter() {
+ @Override
+ public void windowDestroyNotify(final WindowEvent e) {
+ _isClosing = true;
+ }
+
+ // public void windowResized(final WindowEvent e) {
+ // _newtWindow.invoke(true, new GLRunnable() {
+ //
+ // @Override
+ // public boolean run(GLAutoDrawable glAutoDrawable) {
+ // _canvasRenderer._camera.resize(_newtWindow.getWidth(), _newtWindow.getHeight());
+ // _canvasRenderer._camera.setFrustumPerspective(_canvasRenderer._camera.getFovY(),
+ // (float) _newtWindow.getWidth() / (float) _newtWindow.getHeight(),
+ // _canvasRenderer._camera.getFrustumNear(),
+ // _canvasRenderer._camera.getFrustumFar());
+ // return true;
+ // }
+ // });
+ // }
+ });
+
+ // Request the focus here as it cannot work when the window is not visible
+ _newtWindow.requestFocus();
+ applySettings();
+
+ _canvasRenderer.setContext(getContext());
+
+ _newtWindow.invoke(true, new GLRunnable() {
+ @Override
+ public boolean run(final GLAutoDrawable glAutoDrawable) {
+ _canvasRenderer.init(_settings, true);// true - do swap in renderer.
+ return true;
+ }
+ });
+ _inited = true;
+ }
}
public void draw(final CountDownLatch latch) {
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/image/util/jogl/JoglImageLoader.java b/ardor3d-jogl/src/main/java/com/ardor3d/image/util/jogl/JoglImageLoader.java
new file mode 100644
index 0000000..2d8ef66
--- /dev/null
+++ b/ardor3d-jogl/src/main/java/com/ardor3d/image/util/jogl/JoglImageLoader.java
@@ -0,0 +1,128 @@
+/**
+ * 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 <http://www.ardor3d.com/LICENSE>.
+ */
+
+package com.ardor3d.image.util.jogl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.Buffer;
+import java.nio.ByteBuffer;
+import java.nio.DoubleBuffer;
+import java.nio.FloatBuffer;
+import java.nio.IntBuffer;
+import java.nio.LongBuffer;
+import java.nio.ShortBuffer;
+
+import javax.media.opengl.GLProfile;
+
+import com.ardor3d.image.Image;
+import com.ardor3d.image.PixelDataType;
+import com.ardor3d.image.util.ImageLoader;
+import com.ardor3d.scene.state.jogl.util.JoglTextureUtil;
+import com.ardor3d.util.geom.BufferUtils;
+import com.jogamp.common.nio.Buffers;
+import com.jogamp.opengl.util.texture.TextureData;
+import com.jogamp.opengl.util.texture.TextureIO;
+
+public class JoglImageLoader implements ImageLoader {
+
+ // private static final Logger logger = Logger.getLogger(JoglImageLoader.class.getName());
+
+ private static boolean createOnHeap = false;
+
+ private static final String[] supportedFormats = new String[] { TextureIO.DDS, TextureIO.GIF, TextureIO.JPG,
+ TextureIO.JPG, TextureIO.PAM, TextureIO.PNG, TextureIO.PNG, TextureIO.PPM, TextureIO.SGI, TextureIO.TGA,
+ TextureIO.TIFF };
+
+ public static String[] getSupportedFormats() {
+ return supportedFormats;
+ }
+
+ public static void registerLoader() {}
+
+ public JoglImageLoader() {}
+
+ @Override
+ public Image load(final InputStream is, final boolean flipped) throws IOException {
+ final TextureData textureData = TextureIO.newTextureData(GLProfile.getDefault(), is, true, null);
+ final Buffer textureDataBuffer = textureData.getBuffer();
+ final Image ardorImage = new Image();
+
+ int dataSize = textureDataBuffer.capacity();
+ if (textureDataBuffer instanceof ShortBuffer) {
+ dataSize *= Buffers.SIZEOF_SHORT;
+ } else {
+ if (textureDataBuffer instanceof IntBuffer) {
+ dataSize *= Buffers.SIZEOF_INT;
+ } else {
+ if (textureDataBuffer instanceof LongBuffer) {
+ dataSize *= Buffers.SIZEOF_LONG;
+ } else {
+ if (textureDataBuffer instanceof FloatBuffer) {
+ dataSize *= Buffers.SIZEOF_FLOAT;
+ } else {
+ if (textureDataBuffer instanceof DoubleBuffer) {
+ dataSize *= Buffers.SIZEOF_DOUBLE;
+ }
+ }
+ }
+ }
+ }
+ final ByteBuffer scratch = createOnHeap ? BufferUtils.createByteBufferOnHeap(dataSize) : Buffers
+ .newDirectByteBuffer(dataSize);
+ if (textureDataBuffer instanceof ShortBuffer) {
+ final ShortBuffer shortTextureDataBuffer = (ShortBuffer) textureDataBuffer;
+ while (textureDataBuffer.hasRemaining()) {
+ scratch.putShort(shortTextureDataBuffer.get());
+ }
+ } else {
+ if (textureDataBuffer instanceof IntBuffer) {
+ final IntBuffer intTextureDataBuffer = (IntBuffer) textureDataBuffer;
+ while (textureDataBuffer.hasRemaining()) {
+ scratch.putInt(intTextureDataBuffer.get());
+ }
+ } else {
+ if (textureDataBuffer instanceof LongBuffer) {
+ final LongBuffer longTextureDataBuffer = (LongBuffer) textureDataBuffer;
+ while (textureDataBuffer.hasRemaining()) {
+ scratch.putLong(longTextureDataBuffer.get());
+ }
+ } else {
+ if (textureDataBuffer instanceof FloatBuffer) {
+ final FloatBuffer floatTextureDataBuffer = (FloatBuffer) textureDataBuffer;
+ while (textureDataBuffer.hasRemaining()) {
+ scratch.putFloat(floatTextureDataBuffer.get());
+ }
+ } else {
+ if (textureDataBuffer instanceof DoubleBuffer) {
+ final DoubleBuffer doubleTextureDataBuffer = (DoubleBuffer) textureDataBuffer;
+ while (textureDataBuffer.hasRemaining()) {
+ scratch.putDouble(doubleTextureDataBuffer.get());
+ }
+ } else {
+ if (textureDataBuffer instanceof ByteBuffer) {
+ scratch.put((ByteBuffer) textureDataBuffer);
+ }
+ }
+ }
+ }
+ }
+ }
+ scratch.rewind();
+ textureDataBuffer.rewind();
+ ardorImage.setWidth(textureData.getWidth());
+ ardorImage.setHeight(textureData.getHeight());
+ ardorImage.setData(scratch);
+ ardorImage.setDataFormat(JoglTextureUtil.getImageDataFormat(textureData.getPixelFormat()));
+ // ardorImage.setDataType(JoglTextureUtil.getPixelDataType(textureData.getPixelType()));
+ ardorImage.setDataType(PixelDataType.UnsignedByte);
+ return ardorImage;
+ }
+}
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/input/jogl/JoglNewtKey.java b/ardor3d-jogl/src/main/java/com/ardor3d/input/jogl/JoglNewtKey.java
index 30861a4..837e338 100644
--- a/ardor3d-jogl/src/main/java/com/ardor3d/input/jogl/JoglNewtKey.java
+++ b/ardor3d-jogl/src/main/java/com/ardor3d/input/jogl/JoglNewtKey.java
@@ -10,9 +10,8 @@
package com.ardor3d.input.jogl;
-import com.jogamp.newt.event.KeyEvent;
import com.ardor3d.input.Key;
-
+import com.jogamp.newt.event.KeyEvent;
public enum JoglNewtKey {
@@ -127,15 +126,19 @@ public enum JoglNewtKey {
Z(KeyEvent.VK_Z, Key.Z), //
UNDEFINED(KeyEvent.VK_UNDEFINED, Key.UNKNOWN);
- private final int _newtCode;
+ private final short _newtCode;
private final Key _key;
- private JoglNewtKey(final int newtCode, final Key key) {
+ private JoglNewtKey(final short newtCode, final Key key) {
_newtCode = newtCode;
_key = key;
}
- public static Key findByCode(final int newtCode) {
+ private JoglNewtKey(final int newtCode, final Key key) {
+ this((short) newtCode, key);
+ }
+
+ public static Key findByCode(final short newtCode) {
for (final JoglNewtKey ak : values()) {
if (ak._newtCode == newtCode) {
return ak._key;
@@ -145,6 +148,10 @@ public enum JoglNewtKey {
return Key.UNKNOWN;
}
+ public static Key findByCode(final int newtCode) {
+ return findByCode((short) newtCode);
+ }
+
public int getNewtCode() {
return _newtCode;
}
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 2613f25..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
@@ -54,6 +54,7 @@ public class JoglPbufferTextureRenderer extends AbstractPbufferTextureRenderer {
private static final Logger logger = Logger.getLogger(JoglPbufferTextureRenderer.class.getName());
/* Pbuffer instance */
+ // TODO use javax.media.opengl.GLOffscreenAutoDrawable
private GLPbuffer _pbuffer;
private GLContext _context;
@@ -278,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..faf3761
--- /dev/null
+++ b/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglRenderContext.java
@@ -0,0 +1,37 @@
+/**
+ * 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 <http://www.ardor3d.com/LICENSE>.
+ */
+
+package com.ardor3d.renderer.jogl;
+
+import com.ardor3d.renderer.ContextCapabilities;
+import com.ardor3d.renderer.RenderContext;
+import com.ardor3d.renderer.jogl.state.record.JoglRendererRecord;
+
+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 JoglRendererRecord createRendererRecord() {
+ final JoglRendererRecord rendererRecord = new JoglRendererRecord();
+ return rendererRecord;
+ }
+
+ @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 4747dfd..2d6b357 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;
@@ -51,6 +52,7 @@ import com.ardor3d.renderer.DrawBufferTarget;
import com.ardor3d.renderer.IndexMode;
import com.ardor3d.renderer.RenderContext;
import com.ardor3d.renderer.Renderer;
+import com.ardor3d.renderer.jogl.state.record.JoglRendererRecord;
import com.ardor3d.renderer.queue.RenderBucketType;
import com.ardor3d.renderer.state.BlendState;
import com.ardor3d.renderer.state.ClipState;
@@ -102,6 +104,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;
/**
* <code>JoglRenderer</code> provides an implementation of the <code>Renderer</code> interface using the JOGL API.
@@ -240,48 +243,60 @@ public class JoglRenderer extends AbstractRenderer {
}
public void setOrtho() {
- final GL gl = GLContext.getCurrentGL();
-
if (_inOrthoMode) {
throw new Ardor3dException("Already in Orthographic mode.");
}
// set up ortho mode
- final RendererRecord matRecord = ContextManager.getCurrentContext().getRendererRecord();
+ final JoglRendererRecord matRecord = (JoglRendererRecord) ContextManager.getCurrentContext()
+ .getRendererRecord();
JoglRendererUtil.switchMode(matRecord, GLMatrixFunc.GL_PROJECTION);
- gl.getGL2().glPushMatrix();
- gl.getGL2().glLoadIdentity();
+ matRecord.getMatrixBackend().pushMatrix();
+ matRecord.getMatrixBackend().loadIdentity();
+
final Camera camera = Camera.getCurrentCamera();
final double viewportWidth = camera.getWidth() * (camera.getViewPortRight() - camera.getViewPortLeft());
final double viewportHeight = camera.getHeight() * (camera.getViewPortTop() - camera.getViewPortBottom());
- gl.getGL2().glOrtho(0, viewportWidth, 0, viewportHeight, -1, 1);
+ matRecord.getMatrixBackend().setOrtho(0, viewportWidth, 0, viewportHeight, -1, 1);
JoglRendererUtil.switchMode(matRecord, GLMatrixFunc.GL_MODELVIEW);
- gl.getGL2().glPushMatrix();
- gl.getGL2().glLoadIdentity();
+ matRecord.getMatrixBackend().pushMatrix();
+ matRecord.getMatrixBackend().loadIdentity();
_inOrthoMode = true;
}
public void unsetOrtho() {
- final GL gl = GLContext.getCurrentGL();
-
if (!_inOrthoMode) {
throw new Ardor3dException("Not in Orthographic mode.");
}
// remove ortho mode, and go back to original
// state
- final RendererRecord matRecord = ContextManager.getCurrentContext().getRendererRecord();
+ final JoglRendererRecord matRecord = (JoglRendererRecord) ContextManager.getCurrentContext()
+ .getRendererRecord();
JoglRendererUtil.switchMode(matRecord, GLMatrixFunc.GL_PROJECTION);
- gl.getGL2().glPopMatrix();
+ matRecord.getMatrixBackend().popMatrix();
JoglRendererUtil.switchMode(matRecord, GLMatrixFunc.GL_MODELVIEW);
- gl.getGL2().glPopMatrix();
+ matRecord.getMatrixBackend().popMatrix();
_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) {
@@ -405,10 +420,10 @@ public class JoglRenderer extends AbstractRenderer {
public void applyDefaultColor(final ReadOnlyColorRGBA defaultColor) {
final GL gl = GLContext.getCurrentGL();
if (defaultColor != null) {
- gl.getGL2().glColor4f(defaultColor.getRed(), defaultColor.getGreen(), defaultColor.getBlue(),
+ gl.getGL2ES1().glColor4f(defaultColor.getRed(), defaultColor.getGreen(), defaultColor.getBlue(),
defaultColor.getAlpha());
} else {
- gl.getGL2().glColor4f(1, 1, 1, 1);
+ gl.getGL2ES1().glColor4f(1, 1, 1, 1);
}
}
@@ -581,7 +596,7 @@ public class JoglRenderer extends AbstractRenderer {
GL.GL_UNSIGNED_BYTE, source);
break;
case ThreeDimensional:
- gl.getGL2GL3().glTexSubImage3D(GL2ES2.GL_TEXTURE_3D, 0, dstOffsetX, dstOffsetY, dstOffsetZ,
+ gl.getGL2ES2().glTexSubImage3D(GL2ES2.GL_TEXTURE_3D, 0, dstOffsetX, dstOffsetY, dstOffsetZ,
dstWidth, dstHeight, dstDepth, pixelFormat, GL.GL_UNSIGNED_BYTE, source);
break;
case CubeMap:
@@ -645,17 +660,16 @@ public class JoglRenderer extends AbstractRenderer {
}
public boolean doTransforms(final ReadOnlyTransform transform) {
- final GL gl = GLContext.getCurrentGL();
-
// set world matrix
if (!transform.isIdentity()) {
synchronized (_transformMatrix) {
transform.getGLApplyMatrix(_transformBuffer);
- final RendererRecord matRecord = ContextManager.getCurrentContext().getRendererRecord();
+ final JoglRendererRecord matRecord = (JoglRendererRecord) ContextManager.getCurrentContext()
+ .getRendererRecord();
JoglRendererUtil.switchMode(matRecord, GLMatrixFunc.GL_MODELVIEW);
- gl.getGL2().glPushMatrix();
- gl.getGL2().glMultMatrixf(_transformBuffer);
+ matRecord.getMatrixBackend().pushMatrix();
+ matRecord.getMatrixBackend().multMatrix(_transformBuffer);
return true;
}
}
@@ -663,11 +677,10 @@ public class JoglRenderer extends AbstractRenderer {
}
public void undoTransforms(final ReadOnlyTransform transform) {
- final GL gl = GLContext.getCurrentGL();
-
- final RendererRecord matRecord = ContextManager.getCurrentContext().getRendererRecord();
+ final JoglRendererRecord matRecord = (JoglRendererRecord) ContextManager.getCurrentContext()
+ .getRendererRecord();
JoglRendererUtil.switchMode(matRecord, GLMatrixFunc.GL_MODELVIEW);
- gl.getGL2().glPopMatrix();
+ matRecord.getMatrixBackend().popMatrix();
}
public void setupVertexData(final FloatBufferData vertexBufferData) {
@@ -676,11 +689,17 @@ public class JoglRenderer extends AbstractRenderer {
final FloatBuffer vertexBuffer = vertexBufferData != null ? vertexBufferData.getBuffer() : null;
if (vertexBuffer == null) {
- gl.getGL2GL3().glDisableClientState(GLPointerFunc.GL_VERTEX_ARRAY);
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3().glDisableClientState(GLPointerFunc.GL_VERTEX_ARRAY);
+ }
} else {
- gl.getGL2GL3().glEnableClientState(GLPointerFunc.GL_VERTEX_ARRAY);
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3().glEnableClientState(GLPointerFunc.GL_VERTEX_ARRAY);
+ }
vertexBuffer.rewind();
- gl.getGL2().glVertexPointer(vertexBufferData.getValuesPerTuple(), GL.GL_FLOAT, 0, vertexBuffer);
+ if (gl.isGL2ES1()) {
+ gl.getGL2ES1().glVertexPointer(vertexBufferData.getValuesPerTuple(), GL.GL_FLOAT, 0, vertexBuffer);
+ }
}
}
@@ -690,11 +709,17 @@ public class JoglRenderer extends AbstractRenderer {
final FloatBuffer normalBuffer = normalBufferData != null ? normalBufferData.getBuffer() : null;
if (normalBuffer == null) {
- gl.getGL2GL3().glDisableClientState(GLPointerFunc.GL_NORMAL_ARRAY);
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3().glDisableClientState(GLPointerFunc.GL_NORMAL_ARRAY);
+ }
} else {
- gl.getGL2GL3().glEnableClientState(GLPointerFunc.GL_NORMAL_ARRAY);
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3().glEnableClientState(GLPointerFunc.GL_NORMAL_ARRAY);
+ }
normalBuffer.rewind();
- gl.getGL2().glNormalPointer(GL.GL_FLOAT, 0, normalBuffer);
+ if (gl.isGL2ES1()) {
+ gl.getGL2ES1().glNormalPointer(GL.GL_FLOAT, 0, normalBuffer);
+ }
}
}
@@ -704,11 +729,17 @@ public class JoglRenderer extends AbstractRenderer {
final FloatBuffer colorBuffer = colorBufferData != null ? colorBufferData.getBuffer() : null;
if (colorBuffer == null) {
- gl.getGL2GL3().glDisableClientState(GLPointerFunc.GL_COLOR_ARRAY);
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3().glDisableClientState(GLPointerFunc.GL_COLOR_ARRAY);
+ }
} else {
- gl.getGL2GL3().glEnableClientState(GLPointerFunc.GL_COLOR_ARRAY);
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3().glEnableClientState(GLPointerFunc.GL_COLOR_ARRAY);
+ }
colorBuffer.rewind();
- gl.getGL2().glColorPointer(colorBufferData.getValuesPerTuple(), GL.GL_FLOAT, 0, colorBuffer);
+ if (gl.isGL2ES1()) {
+ gl.getGL2ES1().glColorPointer(colorBufferData.getValuesPerTuple(), GL.GL_FLOAT, 0, colorBuffer);
+ }
}
}
@@ -718,11 +749,17 @@ public class JoglRenderer extends AbstractRenderer {
final FloatBuffer fogBuffer = fogBufferData != null ? fogBufferData.getBuffer() : null;
if (fogBuffer == null) {
- gl.getGL2GL3().glDisableClientState(GL2.GL_FOG_COORDINATE_ARRAY);
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3().glDisableClientState(GL2.GL_FOG_COORDINATE_ARRAY);
+ }
} else {
- gl.getGL2GL3().glEnableClientState(GL2.GL_FOG_COORDINATE_ARRAY);
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3().glEnableClientState(GL2.GL_FOG_COORDINATE_ARRAY);
+ }
fogBuffer.rewind();
- gl.getGL2().glFogCoordPointer(GL.GL_FLOAT, 0, fogBuffer);
+ if (gl.isGL2()) {
+ gl.getGL2().glFogCoordPointer(GL.GL_FLOAT, 0, fogBuffer);
+ }
}
}
@@ -755,7 +792,9 @@ public class JoglRenderer extends AbstractRenderer {
enabledTextures &= ~(2 << i);
// disable state
- gl.getGL2GL3().glDisableClientState(GLPointerFunc.GL_TEXTURE_COORD_ARRAY);
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3().glDisableClientState(GLPointerFunc.GL_TEXTURE_COORD_ARRAY);
+ }
continue;
}
@@ -764,7 +803,9 @@ public class JoglRenderer extends AbstractRenderer {
if (!valid || !wasOn) {
// enable state
- gl.getGL2GL3().glEnableClientState(GLPointerFunc.GL_TEXTURE_COORD_ARRAY);
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3().glEnableClientState(GLPointerFunc.GL_TEXTURE_COORD_ARRAY);
+ }
// enable bit in tracking int
enabledTextures |= (2 << i);
@@ -773,9 +814,14 @@ public class JoglRenderer extends AbstractRenderer {
final FloatBufferData textureBufferData = textureCoords.get(i);
final FloatBuffer textureBuffer = textureBufferData.getBuffer();
- gl.getGL2GL3().glEnableClientState(GLPointerFunc.GL_TEXTURE_COORD_ARRAY);
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3().glEnableClientState(GLPointerFunc.GL_TEXTURE_COORD_ARRAY);
+ }
textureBuffer.rewind();
- gl.getGL2().glTexCoordPointer(textureBufferData.getValuesPerTuple(), GL.GL_FLOAT, 0, textureBuffer);
+ if (gl.isGL2ES1()) {
+ gl.getGL2ES1().glTexCoordPointer(textureBufferData.getValuesPerTuple(), GL.GL_FLOAT, 0,
+ textureBuffer);
+ }
}
}
}
@@ -802,8 +848,10 @@ public class JoglRenderer extends AbstractRenderer {
if (primcount < 0) {
gl.glDrawElements(glIndexMode, indices.getBufferLimit(), type, indices.getBuffer());
} else {
- gl.getGL2GL3().glDrawElementsInstanced(glIndexMode, indices.getBufferLimit(), type,
- indices.getBuffer(), primcount);
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3().glDrawElementsInstanced(glIndexMode, indices.getBufferLimit(), type,
+ indices.getBuffer(), primcount);
+ }
}
if (Constants.stats) {
@@ -823,7 +871,10 @@ public class JoglRenderer extends AbstractRenderer {
if (primcount < 0) {
gl.glDrawElements(glIndexMode, count, type, indices.getBuffer());
} else {
- gl.getGL2GL3().glDrawElementsInstanced(glIndexMode, count, type, indices.getBuffer(), primcount);
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3()
+ .glDrawElementsInstanced(glIndexMode, count, type, indices.getBuffer(), primcount);
+ }
}
if (Constants.stats) {
@@ -929,11 +980,17 @@ public class JoglRenderer extends AbstractRenderer {
final int vboID = setupVBO(data, context);
if (vboID != 0) {
- gl.getGL2GL3().glEnableClientState(GLPointerFunc.GL_VERTEX_ARRAY);
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3().glEnableClientState(GLPointerFunc.GL_VERTEX_ARRAY);
+ }
JoglRendererUtil.setBoundVBO(rendRecord, vboID);
- gl.getGL2().glVertexPointer(data.getValuesPerTuple(), GL.GL_FLOAT, 0, 0);
+ if (gl.isGL2ES1()) {
+ gl.getGL2ES1().glVertexPointer(data.getValuesPerTuple(), GL.GL_FLOAT, 0, 0);
+ }
} else {
- gl.getGL2GL3().glDisableClientState(GLPointerFunc.GL_VERTEX_ARRAY);
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3().glDisableClientState(GLPointerFunc.GL_VERTEX_ARRAY);
+ }
}
}
@@ -946,11 +1003,17 @@ public class JoglRenderer extends AbstractRenderer {
final int vboID = setupVBO(data, context);
if (vboID != 0) {
- gl.getGL2GL3().glEnableClientState(GLPointerFunc.GL_NORMAL_ARRAY);
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3().glEnableClientState(GLPointerFunc.GL_NORMAL_ARRAY);
+ }
JoglRendererUtil.setBoundVBO(rendRecord, vboID);
- gl.getGL2().glNormalPointer(GL.GL_FLOAT, 0, 0);
+ if (gl.isGL2ES1()) {
+ gl.getGL2ES1().glNormalPointer(GL.GL_FLOAT, 0, 0);
+ }
} else {
- gl.getGL2GL3().glDisableClientState(GLPointerFunc.GL_NORMAL_ARRAY);
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3().glDisableClientState(GLPointerFunc.GL_NORMAL_ARRAY);
+ }
}
}
@@ -963,11 +1026,17 @@ public class JoglRenderer extends AbstractRenderer {
final int vboID = setupVBO(data, context);
if (vboID != 0) {
- gl.getGL2GL3().glEnableClientState(GLPointerFunc.GL_COLOR_ARRAY);
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3().glEnableClientState(GLPointerFunc.GL_COLOR_ARRAY);
+ }
JoglRendererUtil.setBoundVBO(rendRecord, vboID);
- gl.getGL2().glColorPointer(data.getValuesPerTuple(), GL.GL_FLOAT, 0, 0);
+ if (gl.isGL2ES1()) {
+ gl.getGL2ES1().glColorPointer(data.getValuesPerTuple(), GL.GL_FLOAT, 0, 0);
+ }
} else {
- gl.getGL2GL3().glDisableClientState(GLPointerFunc.GL_COLOR_ARRAY);
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3().glDisableClientState(GLPointerFunc.GL_COLOR_ARRAY);
+ }
}
}
@@ -985,11 +1054,17 @@ public class JoglRenderer extends AbstractRenderer {
final int vboID = setupVBO(data, context);
if (vboID != 0) {
- gl.getGL2GL3().glEnableClientState(GL2.GL_FOG_COORDINATE_ARRAY);
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3().glEnableClientState(GL2.GL_FOG_COORDINATE_ARRAY);
+ }
JoglRendererUtil.setBoundVBO(rendRecord, vboID);
- gl.getGL2().glFogCoordPointer(GL.GL_FLOAT, 0, 0);
+ if (gl.isGL2()) {
+ gl.getGL2().glFogCoordPointer(GL.GL_FLOAT, 0, 0);
+ }
} else {
- gl.getGL2GL3().glDisableClientState(GL2.GL_FOG_COORDINATE_ARRAY);
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3().glDisableClientState(GL2.GL_FOG_COORDINATE_ARRAY);
+ }
}
}
@@ -1021,7 +1096,9 @@ public class JoglRenderer extends AbstractRenderer {
enabledTextures &= ~(2 << i);
// disable state
- gl.getGL2GL3().glDisableClientState(GLPointerFunc.GL_TEXTURE_COORD_ARRAY);
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3().glDisableClientState(GLPointerFunc.GL_TEXTURE_COORD_ARRAY);
+ }
continue;
}
@@ -1039,14 +1116,18 @@ public class JoglRenderer extends AbstractRenderer {
enabledTextures |= (2 << i);
// enable state
- gl.getGL2GL3().glEnableClientState(GLPointerFunc.GL_TEXTURE_COORD_ARRAY);
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3().glEnableClientState(GLPointerFunc.GL_TEXTURE_COORD_ARRAY);
+ }
}
// set our active vbo
JoglRendererUtil.setBoundVBO(rendRecord, vboID);
// send data
- gl.getGL2().glTexCoordPointer(data.getValuesPerTuple(), GL.GL_FLOAT, 0, 0);
+ if (gl.isGL2ES1()) {
+ gl.getGL2ES1().glTexCoordPointer(data.getValuesPerTuple(), GL.GL_FLOAT, 0, 0);
+ }
}
// Not a good vbo, disable it.
else {
@@ -1055,7 +1136,9 @@ public class JoglRenderer extends AbstractRenderer {
enabledTextures &= ~(2 << i);
// disable state
- gl.getGL2GL3().glDisableClientState(GLPointerFunc.GL_TEXTURE_COORD_ARRAY);
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3().glDisableClientState(GLPointerFunc.GL_TEXTURE_COORD_ARRAY);
+ }
}
}
}
@@ -1095,20 +1178,32 @@ public class JoglRenderer extends AbstractRenderer {
if (normalCoords != null) {
updateVBO(normalCoords, rendRecord, vboID, offsetBytes);
- gl.getGL2().glNormalPointer(GL.GL_FLOAT, 0, offsetBytes);
- gl.getGL2GL3().glEnableClientState(GLPointerFunc.GL_NORMAL_ARRAY);
+ if (gl.isGL2ES1()) {
+ gl.getGL2ES1().glNormalPointer(GL.GL_FLOAT, 0, offsetBytes);
+ }
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3().glEnableClientState(GLPointerFunc.GL_NORMAL_ARRAY);
+ }
offsetBytes += normalCoords.getBufferLimit() * 4;
} else {
- gl.getGL2GL3().glDisableClientState(GLPointerFunc.GL_NORMAL_ARRAY);
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3().glDisableClientState(GLPointerFunc.GL_NORMAL_ARRAY);
+ }
}
if (colorCoords != null) {
updateVBO(colorCoords, rendRecord, vboID, offsetBytes);
- gl.getGL2().glColorPointer(colorCoords.getValuesPerTuple(), GL.GL_FLOAT, 0, offsetBytes);
- gl.getGL2GL3().glEnableClientState(GLPointerFunc.GL_COLOR_ARRAY);
+ if (gl.isGL2ES1()) {
+ gl.getGL2ES1().glColorPointer(colorCoords.getValuesPerTuple(), GL.GL_FLOAT, 0, offsetBytes);
+ }
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3().glEnableClientState(GLPointerFunc.GL_COLOR_ARRAY);
+ }
offsetBytes += colorCoords.getBufferLimit() * 4;
} else {
- gl.getGL2GL3().glDisableClientState(GLPointerFunc.GL_COLOR_ARRAY);
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3().glDisableClientState(GLPointerFunc.GL_COLOR_ARRAY);
+ }
}
if (textureCoords != null) {
@@ -1134,7 +1229,9 @@ public class JoglRenderer extends AbstractRenderer {
enabledTextures &= ~(2 << i);
// disable state
- gl.getGL2GL3().glDisableClientState(GLPointerFunc.GL_TEXTURE_COORD_ARRAY);
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3().glDisableClientState(GLPointerFunc.GL_TEXTURE_COORD_ARRAY);
+ }
continue;
}
@@ -1151,12 +1248,16 @@ public class JoglRenderer extends AbstractRenderer {
enabledTextures |= (2 << i);
// enable state
- gl.getGL2GL3().glEnableClientState(GLPointerFunc.GL_TEXTURE_COORD_ARRAY);
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3().glEnableClientState(GLPointerFunc.GL_TEXTURE_COORD_ARRAY);
+ }
}
// send data
- gl.getGL2().glTexCoordPointer(textureBufferData.getValuesPerTuple(), GL.GL_FLOAT, 0,
- offsetBytes);
+ if (gl.isGL2ES1()) {
+ gl.getGL2ES1().glTexCoordPointer(textureBufferData.getValuesPerTuple(), GL.GL_FLOAT, 0,
+ offsetBytes);
+ }
offsetBytes += textureBufferData.getBufferLimit() * 4;
}
}
@@ -1168,10 +1269,16 @@ public class JoglRenderer extends AbstractRenderer {
if (vertexCoords != null) {
updateVBO(vertexCoords, rendRecord, vboID, offsetBytes);
- gl.getGL2().glVertexPointer(vertexCoords.getValuesPerTuple(), GL.GL_FLOAT, 0, offsetBytes);
- gl.getGL2GL3().glEnableClientState(GLPointerFunc.GL_VERTEX_ARRAY);
+ if (gl.isGL2ES1()) {
+ gl.getGL2ES1().glVertexPointer(vertexCoords.getValuesPerTuple(), GL.GL_FLOAT, 0, offsetBytes);
+ }
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3().glEnableClientState(GLPointerFunc.GL_VERTEX_ARRAY);
+ }
} else {
- gl.getGL2GL3().glDisableClientState(GLPointerFunc.GL_VERTEX_ARRAY);
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3().glDisableClientState(GLPointerFunc.GL_VERTEX_ARRAY);
+ }
}
}
@@ -1256,8 +1363,10 @@ public class JoglRenderer extends AbstractRenderer {
if (primcount < 0) {
gl.glDrawElements(glIndexMode, indices.getBufferLimit(), type, 0);
} else {
- gl.getGL2GL3().glDrawElementsInstanced(glIndexMode, indices.getBufferLimit(), type,
- indices.getBuffer(), primcount);
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3().glDrawElementsInstanced(glIndexMode, indices.getBufferLimit(), type,
+ indices.getBuffer(), primcount);
+ }
}
if (Constants.stats) {
@@ -1281,7 +1390,10 @@ public class JoglRenderer extends AbstractRenderer {
} else {
final int previousPos = indices.getBuffer().position();
indices.getBuffer().position(offset * byteSize);
- gl.getGL2GL3().glDrawElementsInstanced(glIndexMode, count, type, indices.getBuffer(), primcount);
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3()
+ .glDrawElementsInstanced(glIndexMode, count, type, indices.getBuffer(), primcount);
+ }
indices.getBuffer().position(previousPos);
}
@@ -1308,7 +1420,9 @@ public class JoglRenderer extends AbstractRenderer {
if (primcount < 0) {
gl.glDrawArrays(glIndexMode, 0, vertexBuffer.getTupleCount());
} else {
- gl.getGL2GL3().glDrawArraysInstanced(glIndexMode, 0, vertexBuffer.getTupleCount(), primcount);
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3().glDrawArraysInstanced(glIndexMode, 0, vertexBuffer.getTupleCount(), primcount);
+ }
}
if (Constants.stats) {
@@ -1325,7 +1439,9 @@ public class JoglRenderer extends AbstractRenderer {
if (primcount < 0) {
gl.glDrawArrays(glIndexMode, offset, count);
} else {
- gl.getGL2GL3().glDrawArraysInstanced(glIndexMode, offset, count, primcount);
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3().glDrawArraysInstanced(glIndexMode, offset, count, primcount);
+ }
}
if (Constants.stats) {
@@ -1437,21 +1553,25 @@ public class JoglRenderer extends AbstractRenderer {
}
public void setModelViewMatrix(final FloatBuffer matrix) {
- final RendererRecord matRecord = ContextManager.getCurrentContext().getRendererRecord();
+ final JoglRendererRecord matRecord = (JoglRendererRecord) ContextManager.getCurrentContext()
+ .getRendererRecord();
JoglRendererUtil.switchMode(matRecord, GLMatrixFunc.GL_MODELVIEW);
loadMatrix(matrix);
}
public void setProjectionMatrix(final FloatBuffer matrix) {
- final RendererRecord matRecord = ContextManager.getCurrentContext().getRendererRecord();
+ final JoglRendererRecord matRecord = (JoglRendererRecord) ContextManager.getCurrentContext()
+ .getRendererRecord();
JoglRendererUtil.switchMode(matRecord, GLMatrixFunc.GL_PROJECTION);
loadMatrix(matrix);
}
private void loadMatrix(final FloatBuffer matrix) {
- GLContext.getCurrentGL().getGL2().glLoadMatrixf(matrix);
+ final JoglRendererRecord matRecord = (JoglRendererRecord) ContextManager.getCurrentContext()
+ .getRendererRecord();
+ matRecord.getMatrixBackend().loadMatrix(matrix);
}
public FloatBuffer getModelViewMatrix(final FloatBuffer store) {
@@ -1467,7 +1587,10 @@ public class JoglRenderer extends AbstractRenderer {
if (result.remaining() < 16) {
result = BufferUtils.createFloatBuffer(16);
}
- GLContext.getCurrentGL().glGetFloatv(matrixType, store);
+ final JoglRendererRecord matRecord = (JoglRendererRecord) ContextManager.getCurrentContext()
+ .getRendererRecord();
+ matRecord.getMatrixBackend().getMatrix(matrixType, store);
+ // GLContext.getCurrentGL().glGetFloatv(matrixType, store);
return result;
}
@@ -1525,7 +1648,10 @@ public class JoglRenderer extends AbstractRenderer {
break;
}
- GLContext.getCurrentGL().getGL2GL3().glDrawBuffer(buffer);
+ final GL gl = GLContext.getCurrentGL();
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3().glDrawBuffer(buffer);
+ }
record.setDrawBufferTarget(target);
}
}
@@ -1585,21 +1711,29 @@ public class JoglRenderer extends AbstractRenderer {
final GL gl = GLContext.getCurrentGL();
// TODO: make this into a pointrecord call
- gl.getGL2GL3().glPointSize(pointSize);
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3().glPointSize(pointSize);
+ }
if (antialiased) {
- gl.glEnable(GL2ES1.GL_POINT_SMOOTH);
- gl.glHint(GL2ES1.GL_POINT_SMOOTH_HINT, GL.GL_NICEST);
+ if (gl.isGL2ES1()) {
+ gl.glEnable(GL2ES1.GL_POINT_SMOOTH);
+ gl.glHint(GL2ES1.GL_POINT_SMOOTH_HINT, GL.GL_NICEST);
+ }
}
if (isSprite && context.getCapabilities().isPointSpritesSupported()) {
- gl.glEnable(GL2ES1.GL_POINT_SPRITE);
- gl.getGL2ES1().glTexEnvi(GL2ES1.GL_POINT_SPRITE, GL2ES1.GL_COORD_REPLACE, GL.GL_TRUE);
+ if (gl.isGL2ES1()) {
+ gl.glEnable(GL2ES1.GL_POINT_SPRITE);
+ gl.getGL2ES1().glTexEnvi(GL2ES1.GL_POINT_SPRITE, GL2ES1.GL_COORD_REPLACE, GL.GL_TRUE);
+ }
}
if (useDistanceAttenuation && context.getCapabilities().isPointParametersSupported()) {
- gl.getGL2GL3().glPointParameterfv(GL2ES1.GL_POINT_DISTANCE_ATTENUATION, attenuationCoefficients);
- gl.getGL2GL3().glPointParameterf(GL2ES1.GL_POINT_SIZE_MIN, minPointSize);
- gl.getGL2GL3().glPointParameterf(GL2ES1.GL_POINT_SIZE_MAX, maxPointSize);
+ if (gl.isGL2GL3()) {
+ gl.getGL2GL3().glPointParameterfv(GL2ES1.GL_POINT_DISTANCE_ATTENUATION, attenuationCoefficients);
+ gl.getGL2GL3().glPointParameterf(GL2ES1.GL_POINT_SIZE_MIN, minPointSize);
+ gl.getGL2GL3().glPointParameterf(GL2ES1.GL_POINT_SIZE_MAX, maxPointSize);
+ }
}
}
@@ -1690,7 +1824,8 @@ public class JoglRenderer extends AbstractRenderer {
* Ends a display list. Will likely cause an OpenGL exception is a display list is not currently being generated.
*/
public void endDisplayList() {
- GLContext.getCurrentGL().getGL2().glEndList();
+ final GL gl = GLContext.getCurrentGL();
+ gl.getGL2().glEndList();
}
/**
@@ -1744,7 +1879,9 @@ public class JoglRenderer extends AbstractRenderer {
public void checkAndSetTextureArrayUnit(final int unit, final GL gl, final RendererRecord record,
final ContextCapabilities caps) {
if (record.getCurrentTextureArraysUnit() != unit && caps.isMultitextureSupported()) {
- gl.getGL2().glClientActiveTexture(GL.GL_TEXTURE0 + unit);
+ if (gl.isGL2ES1()) {
+ gl.getGL2ES1().glClientActiveTexture(GL.GL_TEXTURE0 + unit);
+ }
record.setCurrentTextureArraysUnit(unit);
}
}
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/state/record/JoglMatrixBackend.java b/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/state/record/JoglMatrixBackend.java
new file mode 100644
index 0000000..e70bd71
--- /dev/null
+++ b/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/state/record/JoglMatrixBackend.java
@@ -0,0 +1,32 @@
+/**
+ * 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 <http://www.ardor3d.com/LICENSE>.
+ */
+
+package com.ardor3d.renderer.jogl.state.record;
+
+import java.nio.FloatBuffer;
+
+public interface JoglMatrixBackend {
+
+ public void setMatrixMode(int matrixMode);
+
+ public void pushMatrix();
+
+ public void popMatrix();
+
+ public void multMatrix(FloatBuffer fb);
+
+ public void loadMatrix(FloatBuffer fb);
+
+ public FloatBuffer getMatrix(final int matrixType, final FloatBuffer store);
+
+ public void loadIdentity();
+
+ public void setOrtho(double left, double right, double bottom, double top, double near, double far);
+}
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/state/record/JoglRealMatrixBackend.java b/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/state/record/JoglRealMatrixBackend.java
new file mode 100644
index 0000000..386f7fc
--- /dev/null
+++ b/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/state/record/JoglRealMatrixBackend.java
@@ -0,0 +1,77 @@
+/**
+ * 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 <http://www.ardor3d.com/LICENSE>.
+ */
+
+package com.ardor3d.renderer.jogl.state.record;
+
+import java.nio.FloatBuffer;
+
+import javax.media.opengl.GL2ES1;
+import javax.media.opengl.GLContext;
+
+public class JoglRealMatrixBackend implements JoglMatrixBackend {
+
+ public JoglRealMatrixBackend() {
+ super();
+ if (!GLContext.getCurrentGL().isGL2ES1()) {
+ throw new UnsupportedOperationException("The current GL interface doesn't implement GL2ES1");
+ }
+ }
+
+ @Override
+ public void setMatrixMode(final int matrixMode) {
+ final GL2ES1 gl = GLContext.getCurrentGL().getGL2ES1();
+ gl.glMatrixMode(matrixMode);
+ }
+
+ @Override
+ public void pushMatrix() {
+ final GL2ES1 gl = GLContext.getCurrentGL().getGL2ES1();
+ gl.glPushMatrix();
+ }
+
+ @Override
+ public void popMatrix() {
+ final GL2ES1 gl = GLContext.getCurrentGL().getGL2ES1();
+ gl.glPopMatrix();
+ }
+
+ @Override
+ public void multMatrix(final FloatBuffer fb) {
+ final GL2ES1 gl = GLContext.getCurrentGL().getGL2ES1();
+ gl.glMultMatrixf(fb);
+ }
+
+ @Override
+ public void loadMatrix(final FloatBuffer fb) {
+ final GL2ES1 gl = GLContext.getCurrentGL().getGL2ES1();
+ gl.glLoadMatrixf(fb);
+ }
+
+ @Override
+ public FloatBuffer getMatrix(final int matrixType, final FloatBuffer store) {
+ final GL2ES1 gl = GLContext.getCurrentGL().getGL2ES1();
+ gl.glGetFloatv(matrixType, store);
+ return store;
+ }
+
+ @Override
+ public void loadIdentity() {
+ final GL2ES1 gl = GLContext.getCurrentGL().getGL2ES1();
+ gl.glLoadIdentity();
+ }
+
+ @Override
+ public void setOrtho(final double left, final double right, final double bottom, final double top,
+ final double near, final double far) {
+ final GL2ES1 gl = GLContext.getCurrentGL().getGL2ES1();
+ gl.glOrtho(left, right, bottom, top, near, far);
+ }
+
+}
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/state/record/JoglRendererRecord.java b/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/state/record/JoglRendererRecord.java
new file mode 100644
index 0000000..56a151c
--- /dev/null
+++ b/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/state/record/JoglRendererRecord.java
@@ -0,0 +1,34 @@
+/**
+ * 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 <http://www.ardor3d.com/LICENSE>.
+ */
+
+package com.ardor3d.renderer.jogl.state.record;
+
+import javax.media.opengl.GL;
+import javax.media.opengl.GLContext;
+
+import com.ardor3d.renderer.state.record.RendererRecord;
+
+public class JoglRendererRecord extends RendererRecord {
+
+ protected final JoglMatrixBackend _matrixBackend;
+
+ public JoglRendererRecord() {
+ final GL gl = GLContext.getCurrentGL();
+ if (gl.isGL2ES1()) {
+ _matrixBackend = new JoglRealMatrixBackend();
+ } else {
+ _matrixBackend = new JoglSimulatedMatrixBackend();
+ }
+ }
+
+ public JoglMatrixBackend getMatrixBackend() {
+ return _matrixBackend;
+ }
+}
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/state/record/JoglSimulatedMatrixBackend.java b/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/state/record/JoglSimulatedMatrixBackend.java
new file mode 100644
index 0000000..441f786
--- /dev/null
+++ b/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/state/record/JoglSimulatedMatrixBackend.java
@@ -0,0 +1,68 @@
+/**
+ * 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 <http://www.ardor3d.com/LICENSE>.
+ */
+
+package com.ardor3d.renderer.jogl.state.record;
+
+import java.nio.FloatBuffer;
+
+import com.jogamp.opengl.util.PMVMatrix;
+
+public class JoglSimulatedMatrixBackend implements JoglMatrixBackend {
+
+ private final PMVMatrix _matrix;
+
+ public JoglSimulatedMatrixBackend() {
+ super();
+ _matrix = new PMVMatrix();
+ }
+
+ @Override
+ public void setMatrixMode(final int matrixMode) {
+ _matrix.glMatrixMode(matrixMode);
+ }
+
+ @Override
+ public void pushMatrix() {
+ _matrix.glPushMatrix();
+ }
+
+ @Override
+ public void popMatrix() {
+ _matrix.glPopMatrix();
+ }
+
+ @Override
+ public void multMatrix(final FloatBuffer fb) {
+ _matrix.glMultMatrixf(fb);
+ }
+
+ @Override
+ public void loadMatrix(final FloatBuffer fb) {
+ _matrix.glLoadMatrixf(fb);
+ }
+
+ @Override
+ public FloatBuffer getMatrix(final int matrixType, final FloatBuffer store) {
+ _matrix.glGetFloatv(matrixType, store);
+ return store;
+ }
+
+ @Override
+ public void loadIdentity() {
+ _matrix.glLoadIdentity();
+ }
+
+ @Override
+ public void setOrtho(final double left, final double right, final double bottom, final double top,
+ final double near, final double far) {
+ _matrix.glOrthof((float) left, (float) right, (float) bottom, (float) top, (float) near, (float) far);
+ }
+
+}
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglBlendStateUtil.java b/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglBlendStateUtil.java
index bde9535..4d7f834 100644
--- a/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglBlendStateUtil.java
+++ b/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglBlendStateUtil.java
@@ -128,8 +128,10 @@ public abstract class JoglBlendStateUtil {
if (applyConstant && caps.isConstantBlendColorSupported()) {
final ReadOnlyColorRGBA constant = state.getConstantColor();
if (!record.isValid() || (caps.isConstantBlendColorSupported() && !record.blendColor.equals(constant))) {
- gl.getGL2GL3().glBlendColor(constant.getRed(), constant.getGreen(), constant.getBlue(),
- constant.getAlpha());
+ if (gl.isGL2ES2()) {
+ gl.getGL2ES2().glBlendColor(constant.getRed(), constant.getGreen(), constant.getBlue(),
+ constant.getAlpha());
+ }
record.blendColor.set(constant);
}
}
@@ -372,30 +374,42 @@ public abstract class JoglBlendStateUtil {
if (record.isValid()) {
if (enabled) {
if (!record.testEnabled) {
- gl.glEnable(GL2ES1.GL_ALPHA_TEST);
+ if (gl.isGL2ES1()) {
+ gl.glEnable(GL2ES1.GL_ALPHA_TEST);
+ }
record.testEnabled = true;
}
final int glFunc = getGLFuncValue(state.getTestFunction());
if (record.alphaFunc != glFunc || record.alphaRef != state.getReference()) {
- gl.getGL2().glAlphaFunc(glFunc, state.getReference());
+ if (gl.isGL2ES1()) {
+ gl.getGL2ES1().glAlphaFunc(glFunc, state.getReference());
+ }
record.alphaFunc = glFunc;
record.alphaRef = state.getReference();
}
} else if (record.testEnabled) {
- gl.glDisable(GL2ES1.GL_ALPHA_TEST);
+ if (gl.isGL2ES1()) {
+ gl.glDisable(GL2ES1.GL_ALPHA_TEST);
+ }
record.testEnabled = false;
}
} else {
if (enabled) {
- gl.glEnable(GL2ES1.GL_ALPHA_TEST);
+ if (gl.isGL2ES1()) {
+ gl.glEnable(GL2ES1.GL_ALPHA_TEST);
+ }
record.testEnabled = true;
final int glFunc = getGLFuncValue(state.getTestFunction());
- gl.getGL2().glAlphaFunc(glFunc, state.getReference());
+ if (gl.isGL2ES1()) {
+ gl.getGL2ES1().glAlphaFunc(glFunc, state.getReference());
+ }
record.alphaFunc = glFunc;
record.alphaRef = state.getReference();
} else {
- gl.glDisable(GL2ES1.GL_ALPHA_TEST);
+ if (gl.isGL2ES1()) {
+ gl.glDisable(GL2ES1.GL_ALPHA_TEST);
+ }
record.testEnabled = false;
}
}
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglClipStateUtil.java b/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglClipStateUtil.java
index a64cf95..8dfc993 100644
--- a/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglClipStateUtil.java
+++ b/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglClipStateUtil.java
@@ -54,18 +54,25 @@ public abstract class JoglClipStateUtil {
if (enable) {
if (!record.isValid() || !record.planeEnabled[planeIndex]) {
- gl.glEnable(GL2ES1.GL_CLIP_PLANE0 + planeIndex);
+ if (gl.isGL2ES1()) {
+ gl.glEnable(GL2ES1.GL_CLIP_PLANE0 + planeIndex);
+ }
record.planeEnabled[planeIndex] = true;
}
record.buf.rewind();
record.buf.put(state.getPlaneEquations(planeIndex));
record.buf.flip();
- gl.getGL2().glClipPlane(GL2ES1.GL_CLIP_PLANE0 + planeIndex, record.buf);
+ if (gl.isGL2ES1()) {
+ // TODO Shouldn't glClipPlane be in GL2ES1?
+ gl.getGL2().glClipPlane(GL2ES1.GL_CLIP_PLANE0 + planeIndex, record.buf);
+ }
} else {
if (!record.isValid() || record.planeEnabled[planeIndex]) {
- gl.glDisable(GL2ES1.GL_CLIP_PLANE0 + planeIndex);
+ if (gl.isGL2ES1()) {
+ gl.glDisable(GL2ES1.GL_CLIP_PLANE0 + planeIndex);
+ }
record.planeEnabled[planeIndex] = false;
}
}
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 bb5fa05..8d8dccb 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
@@ -46,31 +46,63 @@ public abstract class JoglShaderObjectsStateUtil {
}
if (state._programID == -1) {
- state._programID = gl.getGL2().glCreateProgramObjectARB();
+ if (gl.isGL2()) {
+ state._programID = gl.getGL2().glCreateProgramObjectARB();
+ } else {
+ if (gl.isGL2ES2()) {
+ state._programID = gl.getGL2ES2().glCreateProgram();
+ }
+ }
}
if (state.getVertexShader() != null) {
if (state._vertexShaderID != -1) {
removeVertShader(state);
}
-
- state._vertexShaderID = gl.getGL2().glCreateShaderObjectARB(GL2ES2.GL_VERTEX_SHADER);
+ if (gl.isGL2()) {
+ state._vertexShaderID = gl.getGL2().glCreateShaderObjectARB(GL2ES2.GL_VERTEX_SHADER);
+ } else {
+ if (gl.isGL2ES2()) {
+ state._vertexShaderID = gl.getGL2ES2().glCreateShader(GL2ES2.GL_VERTEX_SHADER);
+ }
+ }
// Create the sources
final byte array[] = new byte[state.getVertexShader().limit()];
state.getVertexShader().rewind();
state.getVertexShader().get(array);
- gl.getGL2().glShaderSourceARB(state._vertexShaderID, 1, new String[] { new String(array) },
- new int[] { array.length }, 0);
+ if (gl.isGL2()) {
+ gl.getGL2().glShaderSourceARB(state._vertexShaderID, 1, new String[] { new String(array) },
+ new int[] { array.length }, 0);
+ } else {
+ if (gl.isGL2ES2()) {
+ gl.getGL2ES2().glShaderSource(state._vertexShaderID, 1, new String[] { new String(array) },
+ new int[] { array.length }, 0);
+ }
+ }
// Compile the vertex shader
final IntBuffer compiled = BufferUtils.createIntBuffer(1);
- gl.getGL2().glCompileShaderARB(state._vertexShaderID);
- gl.getGL2().glGetObjectParameterivARB(state._vertexShaderID, GL2.GL_OBJECT_COMPILE_STATUS_ARB, compiled);
+ if (gl.isGL2()) {
+ gl.getGL2().glCompileShaderARB(state._vertexShaderID);
+ gl.getGL2()
+ .glGetObjectParameterivARB(state._vertexShaderID, GL2.GL_OBJECT_COMPILE_STATUS_ARB, compiled);
+ } else {
+ if (gl.isGL2ES2()) {
+ gl.getGL2ES2().glCompileShader(state._vertexShaderID);
+ gl.getGL2ES2().glGetShaderiv(state._vertexShaderID, GL2ES2.GL_COMPILE_STATUS, compiled);
+ }
+ }
checkProgramError(compiled, state._vertexShaderID, state._vertexShaderName);
// Attach the program
- gl.getGL2().glAttachObjectARB(state._programID, state._vertexShaderID);
+ if (gl.isGL2()) {
+ gl.getGL2().glAttachObjectARB(state._programID, state._vertexShaderID);
+ } else {
+ if (gl.isGL2ES2()) {
+ gl.getGL2ES2().glAttachShader(state._programID, state._vertexShaderID);
+ }
+ }
} else if (state._vertexShaderID != -1) {
removeVertShader(state);
state._vertexShaderID = -1;
@@ -81,23 +113,50 @@ public abstract class JoglShaderObjectsStateUtil {
removeFragShader(state);
}
- state._fragmentShaderID = gl.getGL2().glCreateShaderObjectARB(GL2ES2.GL_FRAGMENT_SHADER);
+ if (gl.isGL2()) {
+ state._fragmentShaderID = gl.getGL2().glCreateShaderObjectARB(GL2ES2.GL_FRAGMENT_SHADER);
+ } else {
+ if (gl.isGL2ES2()) {
+ state._fragmentShaderID = gl.getGL2ES2().glCreateShader(GL2ES2.GL_FRAGMENT_SHADER);
+ }
+ }
// Create the sources
final byte array[] = new byte[state.getFragmentShader().limit()];
state.getFragmentShader().rewind();
state.getFragmentShader().get(array);
- gl.getGL2().glShaderSourceARB(state._fragmentShaderID, 1, new String[] { new String(array) },
- new int[] { array.length }, 0);
+ if (gl.isGL2()) {
+ gl.getGL2().glShaderSourceARB(state._fragmentShaderID, 1, new String[] { new String(array) },
+ new int[] { array.length }, 0);
+ } else {
+ if (gl.isGL2ES2()) {
+ gl.getGL2ES2().glShaderSource(state._fragmentShaderID, 1, new String[] { new String(array) },
+ new int[] { array.length }, 0);
+ }
+ }
// Compile the fragment shader
final IntBuffer compiled = BufferUtils.createIntBuffer(1);
- gl.getGL2().glCompileShaderARB(state._fragmentShaderID);
- gl.getGL2().glGetObjectParameterivARB(state._fragmentShaderID, GL2.GL_OBJECT_COMPILE_STATUS_ARB, compiled);
+ if (gl.isGL2()) {
+ gl.getGL2().glCompileShaderARB(state._fragmentShaderID);
+ gl.getGL2().glGetObjectParameterivARB(state._fragmentShaderID, GL2.GL_OBJECT_COMPILE_STATUS_ARB,
+ compiled);
+ } else {
+ if (gl.isGL2ES2()) {
+ gl.getGL2ES2().glCompileShader(state._fragmentShaderID);
+ gl.getGL2ES2().glGetShaderiv(state._fragmentShaderID, GL2ES2.GL_COMPILE_STATUS, compiled);
+ }
+ }
checkProgramError(compiled, state._fragmentShaderID, state._vertexShaderName);
// Attach the program
- gl.getGL2().glAttachObjectARB(state._programID, state._fragmentShaderID);
+ if (gl.isGL2()) {
+ gl.getGL2().glAttachObjectARB(state._programID, state._fragmentShaderID);
+ } else {
+ if (gl.isGL2ES2()) {
+ gl.getGL2ES2().glAttachShader(state._programID, state._fragmentShaderID);
+ }
+ }
} else if (state._fragmentShaderID != -1) {
removeFragShader(state);
state._fragmentShaderID = -1;
@@ -109,24 +168,50 @@ public abstract class JoglShaderObjectsStateUtil {
removeGeomShader(state);
}
- state._geometryShaderID = gl.getGL2().glCreateShaderObjectARB(GL3.GL_GEOMETRY_SHADER);
+ if (gl.isGL2()) {
+ state._geometryShaderID = gl.getGL2().glCreateShaderObjectARB(GL3.GL_GEOMETRY_SHADER);
+ } else {
+ if (gl.isGL2ES2()) {
+ state._geometryShaderID = gl.getGL2ES2().glCreateShader(GL3.GL_GEOMETRY_SHADER);
+ }
+ }
// Create the sources
final byte array[] = new byte[state.getGeometryShader().limit()];
state.getGeometryShader().rewind();
state.getGeometryShader().get(array);
- gl.getGL2().glShaderSourceARB(state._geometryShaderID, 1, new String[] { new String(array) },
- new int[] { array.length }, 0);
+ if (gl.isGL2()) {
+ gl.getGL2().glShaderSourceARB(state._geometryShaderID, 1, new String[] { new String(array) },
+ new int[] { array.length }, 0);
+ } else {
+ if (gl.isGL2ES2()) {
+ gl.getGL2ES2().glShaderSource(state._geometryShaderID, 1, new String[] { new String(array) },
+ new int[] { array.length }, 0);
+ }
+ }
// Compile the geometry shader
final IntBuffer compiled = BufferUtils.createIntBuffer(1);
- gl.getGL2().glCompileShaderARB(state._geometryShaderID);
- gl.getGL2().glGetObjectParameterivARB(state._geometryShaderID, GL2.GL_OBJECT_COMPILE_STATUS_ARB,
- compiled);
+ if (gl.isGL2()) {
+ gl.getGL2().glCompileShaderARB(state._geometryShaderID);
+ gl.getGL2().glGetObjectParameterivARB(state._geometryShaderID, GL2.GL_OBJECT_COMPILE_STATUS_ARB,
+ compiled);
+ } else {
+ if (gl.isGL2ES2()) {
+ gl.getGL2ES2().glCompileShader(state._geometryShaderID);
+ gl.getGL2ES2().glGetShaderiv(state._geometryShaderID, GL2ES2.GL_COMPILE_STATUS, compiled);
+ }
+ }
checkProgramError(compiled, state._geometryShaderID, state._geometryShaderName);
// Attach the program
- gl.getGL2().glAttachObjectARB(state._programID, state._geometryShaderID);
+ if (gl.isGL2()) {
+ gl.getGL2().glAttachObjectARB(state._programID, state._geometryShaderID);
+ } else {
+ if (gl.isGL2ES2()) {
+ gl.getGL2ES2().glAttachShader(state._programID, state._geometryShaderID);
+ }
+ }
} else if (state._geometryShaderID != -1) {
removeGeomShader(state);
state._geometryShaderID = -1;
@@ -139,24 +224,52 @@ public abstract class JoglShaderObjectsStateUtil {
removeTessControlShader(state);
}
- state._tessellationControlShaderID = gl.getGL2().glCreateShaderObjectARB(GL3.GL_TESS_CONTROL_SHADER);
+ if (gl.isGL2()) {
+ state._tessellationControlShaderID = gl.getGL2()
+ .glCreateShaderObjectARB(GL3.GL_TESS_CONTROL_SHADER);
+ } else {
+ if (gl.isGL2ES2()) {
+ state._tessellationControlShaderID = gl.getGL2ES2().glCreateShader(GL3.GL_TESS_CONTROL_SHADER);
+ }
+ }
// Create the sources
final byte array[] = new byte[state.getTessellationControlShader().limit()];
state.getTessellationControlShader().rewind();
state.getTessellationControlShader().get(array);
- gl.getGL2().glShaderSourceARB(state._tessellationControlShaderID, 1,
- new String[] { new String(array) }, new int[] { array.length }, 0);
+ if (gl.isGL2()) {
+ gl.getGL2().glShaderSourceARB(state._tessellationControlShaderID, 1,
+ new String[] { new String(array) }, new int[] { array.length }, 0);
+ } else {
+ if (gl.isGL2ES2()) {
+ gl.getGL2ES2().glShaderSource(state._tessellationControlShaderID, 1,
+ new String[] { new String(array) }, new int[] { array.length }, 0);
+ }
+ }
// Compile the tessellation control shader
final IntBuffer compiled = BufferUtils.createIntBuffer(1);
- gl.getGL2().glCompileShaderARB(state._tessellationControlShaderID);
- gl.getGL2().glGetObjectParameterivARB(state._tessellationControlShaderID,
- GL2.GL_OBJECT_COMPILE_STATUS_ARB, compiled);
+ if (gl.isGL2()) {
+ gl.getGL2().glCompileShaderARB(state._tessellationControlShaderID);
+ gl.getGL2().glGetObjectParameterivARB(state._tessellationControlShaderID,
+ GL2.GL_OBJECT_COMPILE_STATUS_ARB, compiled);
+ } else {
+ if (gl.isGL2ES2()) {
+ gl.getGL2ES2().glCompileShader(state._tessellationControlShaderID);
+ gl.getGL2ES2().glGetShaderiv(state._tessellationControlShaderID, GL2ES2.GL_COMPILE_STATUS,
+ compiled);
+ }
+ }
checkProgramError(compiled, state._tessellationControlShaderID, state._tessellationControlShaderName);
// Attach the program
- gl.getGL2().glAttachObjectARB(state._programID, state._tessellationControlShaderID);
+ if (gl.isGL2()) {
+ gl.getGL2().glAttachObjectARB(state._programID, state._tessellationControlShaderID);
+ } else {
+ if (gl.isGL2ES2()) {
+ gl.getGL2ES2().glAttachShader(state._programID, state._tessellationControlShaderID);
+ }
+ }
} else if (state._tessellationControlShaderID != -1) {
removeTessControlShader(state);
state._tessellationControlShaderID = -1;
@@ -166,32 +279,67 @@ public abstract class JoglShaderObjectsStateUtil {
removeTessEvalShader(state);
}
- state._tessellationEvaluationShaderID = gl.getGL2().glCreateShaderObjectARB(GL3.GL_TESS_CONTROL_SHADER);
+ if (gl.isGL2()) {
+ state._tessellationEvaluationShaderID = gl.getGL2().glCreateShaderObjectARB(
+ GL3.GL_TESS_CONTROL_SHADER);
+ } else {
+ if (gl.isGL2ES2()) {
+ state._tessellationEvaluationShaderID = gl.getGL2ES2().glCreateShader(
+ GL3.GL_TESS_CONTROL_SHADER);
+ }
+ }
// Create the sources
final byte array[] = new byte[state.getTessellationEvaluationShader().limit()];
state.getTessellationEvaluationShader().rewind();
state.getTessellationEvaluationShader().get(array);
- gl.getGL2().glShaderSourceARB(state._tessellationEvaluationShaderID, 1,
- new String[] { new String(array) }, new int[] { array.length }, 0);
+ if (gl.isGL2()) {
+ gl.getGL2().glShaderSourceARB(state._tessellationEvaluationShaderID, 1,
+ new String[] { new String(array) }, new int[] { array.length }, 0);
+ } else {
+ if (gl.isGL2ES2()) {
+ gl.getGL2ES2().glShaderSource(state._tessellationEvaluationShaderID, 1,
+ new String[] { new String(array) }, new int[] { array.length }, 0);
+ }
+ }
// Compile the tessellation control shader
final IntBuffer compiled = BufferUtils.createIntBuffer(1);
- gl.getGL2().glCompileShaderARB(state._tessellationEvaluationShaderID);
- gl.getGL2().glGetObjectParameterivARB(state._tessellationEvaluationShaderID,
- GL2.GL_OBJECT_COMPILE_STATUS_ARB, compiled);
+ if (gl.isGL2()) {
+ gl.getGL2().glCompileShaderARB(state._tessellationEvaluationShaderID);
+ gl.getGL2().glGetObjectParameterivARB(state._tessellationEvaluationShaderID,
+ GL2.GL_OBJECT_COMPILE_STATUS_ARB, compiled);
+ } else {
+ if (gl.isGL2ES2()) {
+ gl.getGL2ES2().glCompileShader(state._tessellationEvaluationShaderID);
+ gl.getGL2ES2().glGetShaderiv(state._tessellationEvaluationShaderID, GL2ES2.GL_COMPILE_STATUS,
+ compiled);
+ }
+ }
checkProgramError(compiled, state._tessellationEvaluationShaderID,
state._tessellationEvaluationShaderName);
// Attach the program
- gl.getGL2().glAttachObjectARB(state._programID, state._tessellationEvaluationShaderID);
+ if (gl.isGL2()) {
+ gl.getGL2().glAttachObjectARB(state._programID, state._tessellationEvaluationShaderID);
+ } else {
+ if (gl.isGL2ES2()) {
+ gl.getGL2ES2().glAttachShader(state._programID, state._tessellationEvaluationShaderID);
+ }
+ }
} else if (state._tessellationEvaluationShaderID != -1) {
removeTessEvalShader(state);
state._tessellationEvaluationShaderID = -1;
}
}
- gl.getGL2().glLinkProgramARB(state._programID);
+ if (gl.isGL2()) {
+ gl.getGL2().glLinkProgramARB(state._programID);
+ } else {
+ if (gl.isGL2ES2()) {
+ gl.getGL2ES2().glLinkProgram(state._programID);
+ }
+ }
checkLinkError(state._programID);
state.setNeedsRefresh(true);
state._needSendShader = false;
@@ -201,15 +349,32 @@ public abstract class JoglShaderObjectsStateUtil {
final GL gl = GLContext.getCurrentGL();
final IntBuffer compiled = BufferUtils.createIntBuffer(1);
- gl.getGL2().glGetObjectParameterivARB(programId, GL2ES2.GL_LINK_STATUS, compiled);
+ if (gl.isGL2()) {
+ gl.getGL2().glGetObjectParameterivARB(programId, GL2ES2.GL_LINK_STATUS, compiled);
+ } else {
+ if (gl.isGL2ES2()) {
+ gl.getGL2ES2().glGetProgramiv(programId, GL2ES2.GL_LINK_STATUS, compiled);
+ }
+ }
if (compiled.get(0) == GL.GL_FALSE) {
- gl.getGL2().glGetObjectParameterivARB(programId, GL2ES2.GL_INFO_LOG_LENGTH, compiled);
+ if (gl.isGL2()) {
+ gl.getGL2().glGetObjectParameterivARB(programId, GL2ES2.GL_INFO_LOG_LENGTH, compiled);
+ } else {
+ if (gl.isGL2ES2()) {
+ gl.getGL2ES2().glGetProgramiv(programId, GL2ES2.GL_INFO_LOG_LENGTH, compiled);
+ }
+ }
final int length = compiled.get(0);
String out = null;
if (length > 0) {
final ByteBuffer infoLog = BufferUtils.createByteBuffer(length);
-
- gl.getGL2().glGetInfoLogARB(programId, infoLog.limit(), compiled, infoLog);
+ if (gl.isGL2()) {
+ gl.getGL2().glGetInfoLogARB(programId, infoLog.limit(), compiled, infoLog);
+ } else {
+ if (gl.isGL2ES2()) {
+ gl.getGL2ES2().glGetProgramInfoLog(programId, length, null, infoLog);
+ }
+ }
final byte[] infoBytes = new byte[length];
infoLog.get(infoBytes);
@@ -227,8 +392,15 @@ public abstract class JoglShaderObjectsStateUtil {
final GL gl = GLContext.getCurrentGL();
if (state._fragmentShaderID != -1) {
- gl.getGL2().glDetachObjectARB(state._programID, state._fragmentShaderID);
- gl.getGL2().glDeleteObjectARB(state._fragmentShaderID);
+ if (gl.isGL2()) {
+ gl.getGL2().glDetachObjectARB(state._programID, state._fragmentShaderID);
+ gl.getGL2().glDeleteObjectARB(state._fragmentShaderID);
+ } else {
+ if (gl.isGL2ES2()) {
+ gl.getGL2ES2().glDetachShader(state._programID, state._fragmentShaderID);
+ gl.getGL2ES2().glDeleteShader(state._fragmentShaderID);
+ }
+ }
}
}
@@ -237,8 +409,15 @@ public abstract class JoglShaderObjectsStateUtil {
final GL gl = GLContext.getCurrentGL();
if (state._vertexShaderID != -1) {
- gl.getGL2().glDetachObjectARB(state._programID, state._vertexShaderID);
- gl.getGL2().glDeleteObjectARB(state._vertexShaderID);
+ if (gl.isGL2()) {
+ gl.getGL2().glDetachObjectARB(state._programID, state._vertexShaderID);
+ gl.getGL2().glDeleteObjectARB(state._vertexShaderID);
+ } else {
+ if (gl.isGL2ES2()) {
+ gl.getGL2ES2().glDetachShader(state._programID, state._vertexShaderID);
+ gl.getGL2ES2().glDeleteShader(state._vertexShaderID);
+ }
+ }
}
}
@@ -247,8 +426,15 @@ public abstract class JoglShaderObjectsStateUtil {
final GL gl = GLContext.getCurrentGL();
if (state._geometryShaderID != -1) {
- gl.getGL2().glDetachObjectARB(state._programID, state._geometryShaderID);
- gl.getGL2().glDeleteObjectARB(state._geometryShaderID);
+ if (gl.isGL2()) {
+ gl.getGL2().glDetachObjectARB(state._programID, state._geometryShaderID);
+ gl.getGL2().glDeleteObjectARB(state._geometryShaderID);
+ } else {
+ if (gl.isGL2ES2()) {
+ gl.getGL2ES2().glDetachShader(state._programID, state._geometryShaderID);
+ gl.getGL2ES2().glDeleteShader(state._geometryShaderID);
+ }
+ }
}
}
@@ -257,8 +443,15 @@ public abstract class JoglShaderObjectsStateUtil {
final GL gl = GLContext.getCurrentGL();
if (state._tessellationControlShaderID != -1) {
- gl.getGL2().glDetachObjectARB(state._programID, state._tessellationControlShaderID);
- gl.getGL2().glDeleteObjectARB(state._tessellationControlShaderID);
+ if (gl.isGL2()) {
+ gl.getGL2().glDetachObjectARB(state._programID, state._tessellationControlShaderID);
+ gl.getGL2().glDeleteObjectARB(state._tessellationControlShaderID);
+ } else {
+ if (gl.isGL2ES2()) {
+ gl.getGL2ES2().glDetachShader(state._programID, state._tessellationControlShaderID);
+ gl.getGL2ES2().glDeleteShader(state._tessellationControlShaderID);
+ }
+ }
}
}
@@ -267,8 +460,15 @@ public abstract class JoglShaderObjectsStateUtil {
final GL gl = GLContext.getCurrentGL();
if (state._tessellationEvaluationShaderID != -1) {
- gl.getGL2().glDetachObjectARB(state._programID, state._tessellationEvaluationShaderID);
- gl.getGL2().glDeleteObjectARB(state._tessellationEvaluationShaderID);
+ if (gl.isGL2()) {
+ gl.getGL2().glDetachObjectARB(state._programID, state._tessellationEvaluationShaderID);
+ gl.getGL2().glDeleteObjectARB(state._tessellationEvaluationShaderID);
+ } else {
+ if (gl.isGL2ES2()) {
+ gl.getGL2ES2().glDetachShader(state._programID, state._tessellationEvaluationShaderID);
+ gl.getGL2ES2().glDeleteShader(state._tessellationEvaluationShaderID);
+ }
+ }
}
}
@@ -285,14 +485,25 @@ public abstract class JoglShaderObjectsStateUtil {
if (compiled.get(0) == GL.GL_FALSE) {
final IntBuffer iVal = BufferUtils.createIntBuffer(1);
- gl.getGL2().glGetObjectParameterivARB(id, GL2.GL_OBJECT_INFO_LOG_LENGTH_ARB, iVal);
+ 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);
+ }
+ }
final int length = iVal.get(0);
String out = null;
if (length > 0) {
final ByteBuffer infoLog = BufferUtils.createByteBuffer(length);
-
- gl.getGL2().glGetInfoLogARB(id, infoLog.limit(), iVal, infoLog);
+ if (gl.isGL2()) {
+ gl.getGL2().glGetInfoLogARB(id, infoLog.limit(), iVal, infoLog);
+ } else {
+ if (gl.isGL2ES2()) {
+ gl.getGL2ES2().glGetProgramInfoLog(id, length, null, infoLog);
+ }
+ }
final byte[] infoBytes = new byte[length];
infoLog.get(infoBytes);
@@ -374,10 +585,22 @@ public abstract class JoglShaderObjectsStateUtil {
for (int i = 0, maxI = record.enabledAttributes.size(); i < maxI; i++) {
final ShaderVariable var = record.enabledAttributes.get(i);
if (var.getSize() == 1) {
- gl.getGL2().glDisableVertexAttribArrayARB(var.variableID);
+ if (gl.isGL2()) {
+ gl.getGL2().glDisableVertexAttribArrayARB(var.variableID);
+ } else {
+ if (gl.isGL2ES2()) {
+ gl.getGL2ES2().glDisableVertexAttribArray(var.variableID);
+ }
+ }
} else {
for (int j = 0, maxJ = var.getSize(); j < maxJ; j++) {
- gl.getGL2().glDisableVertexAttribArrayARB(var.variableID + j);
+ if (gl.isGL2()) {
+ gl.getGL2().glDisableVertexAttribArrayARB(var.variableID + j);
+ } else {
+ if (gl.isGL2ES2()) {
+ gl.getGL2ES2().glDisableVertexAttribArray(var.variableID + j);
+ }
+ }
}
}
}
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 0cb091c..f17c18b 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
@@ -24,7 +24,6 @@ import javax.media.opengl.GLContext;
import javax.media.opengl.GLException;
import javax.media.opengl.fixedfunc.GLMatrixFunc;
import javax.media.opengl.glu.GLU;
-import javax.media.opengl.glu.gl2.GLUgl2;
import com.ardor3d.image.Image;
import com.ardor3d.image.Texture;
@@ -48,9 +47,9 @@ import com.ardor3d.renderer.ContextCapabilities;
import com.ardor3d.renderer.ContextManager;
import com.ardor3d.renderer.RenderContext;
import com.ardor3d.renderer.jogl.JoglRenderer;
+import com.ardor3d.renderer.jogl.state.record.JoglRendererRecord;
import com.ardor3d.renderer.state.RenderState.StateType;
import com.ardor3d.renderer.state.TextureState;
-import com.ardor3d.renderer.state.record.RendererRecord;
import com.ardor3d.renderer.state.record.TextureRecord;
import com.ardor3d.renderer.state.record.TextureStateRecord;
import com.ardor3d.renderer.state.record.TextureUnitRecord;
@@ -128,7 +127,7 @@ public class JoglTextureStateUtil {
final Texture.Type type = texture.getType();
final GL gl = GLContext.getCurrentGL();
- final GLU glu = new GLUgl2();
+ final GLU glu = GLU.createGLU(gl);
// bind our texture id to this unit.
doTextureBind(texture, unit, false);
@@ -187,6 +186,8 @@ public class JoglTextureStateUtil {
final int pixDataType = JoglTextureUtil.getGLPixelDataType(image.getDataType());
final int bpp = ImageUtils.getPixelByteSize(image.getDataFormat(), image.getDataType());
final ByteBuffer scaledImage = BufferUtils.createByteBuffer((w + 4) * h * bpp);
+ // ensure the buffer is ready for reading
+ image.getData(0).rewind();
final int error = glu.gluScaleImage(pixFormat, actualWidth, actualHeight, pixDataType,
image.getData(0), w, h, pixDataType, scaledImage);
if (error != 0) {
@@ -354,6 +355,7 @@ public class JoglTextureStateUtil {
for (int x = 0; x < image.getData().size(); x++) {
if (image.getData(x) != null) {
data.put(image.getData(x));
+ image.getData(x).rewind();
}
}
// ensure the buffer is ready for reading
@@ -563,11 +565,11 @@ public class JoglTextureStateUtil {
final int depth = Math.max(1, image.getDepth() >> m);
// already checked for support above...
if (texture.getTextureStoreFormat().isCompressed()) {
- gl.getGL2GL3().glCompressedTexImage3D(GL2ES2.GL_TEXTURE_3D, m,
+ gl.getGL2ES2().glCompressedTexImage3D(GL2ES2.GL_TEXTURE_3D, m,
JoglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()),
width, height, depth, hasBorder ? 1 : 0, mipSizes[m], data);
} else {
- gl.getGL2GL3().glTexImage3D(GL2ES2.GL_TEXTURE_3D, m,
+ gl.getGL2ES2().glTexImage3D(GL2ES2.GL_TEXTURE_3D, m,
JoglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()),
width, height, depth, hasBorder ? 1 : 0,
JoglTextureUtil.getGLPixelFormat(image.getDataFormat()),
@@ -1144,7 +1146,8 @@ public class JoglTextureStateUtil {
final boolean doTrans = !texture.getTextureMatrix().isIdentity();
// Now do them.
- final RendererRecord matRecord = ContextManager.getCurrentContext().getRendererRecord();
+ final JoglRendererRecord matRecord = (JoglRendererRecord) ContextManager.getCurrentContext()
+ .getRendererRecord();
if (doTrans) {
checkAndSetUnit(unit, record, caps);
JoglRendererUtil.switchMode(matRecord, GL.GL_TEXTURE);
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/shader/JoglShaderUtil.java b/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/shader/JoglShaderUtil.java
index 006cdb8..4748cd3 100644
--- a/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/shader/JoglShaderUtil.java
+++ b/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/shader/JoglShaderUtil.java
@@ -106,7 +106,7 @@ public abstract class JoglShaderUtil {
final GL gl = GLContext.getCurrentGL();
if (variable.variableID == -1) {
- variable.variableID = gl.getGL2GL3().glGetUniformLocation(programID, variable.name); // TODO Check
+ variable.variableID = gl.getGL2ES2().glGetUniformLocation(programID, variable.name); // TODO Check
// variable.name
if (variable.variableID == -1 && !variable.errorLogged) {
@@ -119,26 +119,26 @@ public abstract class JoglShaderUtil {
private static void updateShaderUniform(final ShaderVariableInt shaderUniform) {
final GL gl = GLContext.getCurrentGL();
- gl.getGL2GL3().glUniform1i(shaderUniform.variableID, shaderUniform.value1);
+ gl.getGL2ES2().glUniform1i(shaderUniform.variableID, shaderUniform.value1);
}
private static void updateShaderUniform(final ShaderVariableInt2 shaderUniform) {
final GL gl = GLContext.getCurrentGL();
- gl.getGL2GL3().glUniform2i(shaderUniform.variableID, shaderUniform.value1, shaderUniform.value2);
+ gl.getGL2ES2().glUniform2i(shaderUniform.variableID, shaderUniform.value1, shaderUniform.value2);
}
private static void updateShaderUniform(final ShaderVariableInt3 shaderUniform) {
final GL gl = GLContext.getCurrentGL();
- gl.getGL2GL3().glUniform3i(shaderUniform.variableID, shaderUniform.value1, shaderUniform.value2,
+ gl.getGL2ES2().glUniform3i(shaderUniform.variableID, shaderUniform.value1, shaderUniform.value2,
shaderUniform.value3);
}
private static void updateShaderUniform(final ShaderVariableInt4 shaderUniform) {
final GL gl = GLContext.getCurrentGL();
- gl.getGL2GL3().glUniform4i(shaderUniform.variableID, shaderUniform.value1, shaderUniform.value2,
+ gl.getGL2ES2().glUniform4i(shaderUniform.variableID, shaderUniform.value1, shaderUniform.value2,
shaderUniform.value3, shaderUniform.value4);
}
@@ -147,19 +147,19 @@ public abstract class JoglShaderUtil {
switch (shaderUniform.size) {
case 1:
- gl.getGL2GL3().glUniform1iv(shaderUniform.variableID, shaderUniform.value.remaining(),
+ gl.getGL2ES2().glUniform1iv(shaderUniform.variableID, shaderUniform.value.remaining(),
shaderUniform.value);
break;
case 2:
- gl.getGL2GL3().glUniform2iv(shaderUniform.variableID, shaderUniform.value.remaining(),
+ gl.getGL2ES2().glUniform2iv(shaderUniform.variableID, shaderUniform.value.remaining(),
shaderUniform.value);
break;
case 3:
- gl.getGL2GL3().glUniform3iv(shaderUniform.variableID, shaderUniform.value.remaining(),
+ gl.getGL2ES2().glUniform3iv(shaderUniform.variableID, shaderUniform.value.remaining(),
shaderUniform.value);
break;
case 4:
- gl.getGL2GL3().glUniform4iv(shaderUniform.variableID, shaderUniform.value.remaining(),
+ gl.getGL2ES2().glUniform4iv(shaderUniform.variableID, shaderUniform.value.remaining(),
shaderUniform.value);
break;
default:
@@ -170,26 +170,26 @@ public abstract class JoglShaderUtil {
private static void updateShaderUniform(final ShaderVariableFloat shaderUniform) {
final GL gl = GLContext.getCurrentGL();
- gl.getGL2GL3().glUniform1f(shaderUniform.variableID, shaderUniform.value1);
+ gl.getGL2ES2().glUniform1f(shaderUniform.variableID, shaderUniform.value1);
}
private static void updateShaderUniform(final ShaderVariableFloat2 shaderUniform) {
final GL gl = GLContext.getCurrentGL();
- gl.getGL2GL3().glUniform2f(shaderUniform.variableID, shaderUniform.value1, shaderUniform.value2);
+ gl.getGL2ES2().glUniform2f(shaderUniform.variableID, shaderUniform.value1, shaderUniform.value2);
}
private static void updateShaderUniform(final ShaderVariableFloat3 shaderUniform) {
final GL gl = GLContext.getCurrentGL();
- gl.getGL2GL3().glUniform3f(shaderUniform.variableID, shaderUniform.value1, shaderUniform.value2,
+ gl.getGL2ES2().glUniform3f(shaderUniform.variableID, shaderUniform.value1, shaderUniform.value2,
shaderUniform.value3);
}
private static void updateShaderUniform(final ShaderVariableFloat4 shaderUniform) {
final GL gl = GLContext.getCurrentGL();
- gl.getGL2GL3().glUniform4f(shaderUniform.variableID, shaderUniform.value1, shaderUniform.value2,
+ gl.getGL2ES2().glUniform4f(shaderUniform.variableID, shaderUniform.value1, shaderUniform.value2,
shaderUniform.value3, shaderUniform.value4);
}
@@ -198,19 +198,19 @@ public abstract class JoglShaderUtil {
switch (shaderUniform.size) {
case 1:
- gl.getGL2GL3().glUniform1fv(shaderUniform.variableID, shaderUniform.value.remaining(),
+ gl.getGL2ES2().glUniform1fv(shaderUniform.variableID, shaderUniform.value.remaining(),
shaderUniform.value);
break;
case 2:
- gl.getGL2GL3().glUniform2fv(shaderUniform.variableID, shaderUniform.value.remaining(),
+ gl.getGL2ES2().glUniform2fv(shaderUniform.variableID, shaderUniform.value.remaining(),
shaderUniform.value);
break;
case 3:
- gl.getGL2GL3().glUniform3fv(shaderUniform.variableID, shaderUniform.value.remaining(),
+ gl.getGL2ES2().glUniform3fv(shaderUniform.variableID, shaderUniform.value.remaining(),
shaderUniform.value);
break;
case 4:
- gl.getGL2GL3().glUniform4fv(shaderUniform.variableID, shaderUniform.value.remaining(),
+ gl.getGL2ES2().glUniform4fv(shaderUniform.variableID, shaderUniform.value.remaining(),
shaderUniform.value);
break;
default:
@@ -222,7 +222,7 @@ public abstract class JoglShaderUtil {
final GL gl = GLContext.getCurrentGL();
shaderUniform.matrixBuffer.rewind();
- gl.getGL2GL3().glUniformMatrix2fv(shaderUniform.variableID, 1, shaderUniform.rowMajor,
+ gl.getGL2ES2().glUniformMatrix2fv(shaderUniform.variableID, 1, shaderUniform.rowMajor,
shaderUniform.matrixBuffer);
}
@@ -230,7 +230,7 @@ public abstract class JoglShaderUtil {
final GL gl = GLContext.getCurrentGL();
shaderUniform.matrixBuffer.rewind();
- gl.getGL2GL3().glUniformMatrix3fv(shaderUniform.variableID, 1, shaderUniform.rowMajor,
+ gl.getGL2ES2().glUniformMatrix3fv(shaderUniform.variableID, 1, shaderUniform.rowMajor,
shaderUniform.matrixBuffer);
}
@@ -238,7 +238,7 @@ public abstract class JoglShaderUtil {
final GL gl = GLContext.getCurrentGL();
shaderUniform.matrixBuffer.rewind();
- gl.getGL2GL3().glUniformMatrix4fv(shaderUniform.variableID, 1, shaderUniform.rowMajor,
+ gl.getGL2ES2().glUniformMatrix4fv(shaderUniform.variableID, 1, shaderUniform.rowMajor,
shaderUniform.matrixBuffer);
}
@@ -247,7 +247,7 @@ public abstract class JoglShaderUtil {
shaderUniform.matrixBuffer.rewind();
// count == number of matrices we are sending, or iotw, limit / 16
- gl.getGL2GL3().glUniformMatrix4fv(shaderUniform.variableID, shaderUniform.matrixBuffer.limit() >> 4,
+ gl.getGL2ES2().glUniformMatrix4fv(shaderUniform.variableID, shaderUniform.matrixBuffer.limit() >> 4,
shaderUniform.rowMajor, shaderUniform.matrixBuffer);
}
@@ -263,7 +263,7 @@ public abstract class JoglShaderUtil {
final GL gl = GLContext.getCurrentGL();
if (variable.variableID == -1) {
- variable.variableID = gl.getGL2GL3().glGetAttribLocation(programID, variable.name); // TODO Check
+ variable.variableID = gl.getGL2ES2().glGetAttribLocation(programID, variable.name); // TODO Check
// variable.name
if (variable.variableID == -1 && !variable.errorLogged) {
@@ -321,7 +321,14 @@ public abstract class JoglShaderUtil {
public static void useShaderProgram(final int id, final ShaderObjectsStateRecord record) {
if (record.shaderId != id) {
- GLContext.getCurrentGL().getGL2().glUseProgramObjectARB(id);
+ final GL gl = GLContext.getCurrentGL();
+ if (gl.isGL2()) {
+ gl.getGL2().glUseProgramObjectARB(id);
+ } else {
+ if (gl.isGL2ES2()) {
+ gl.getGL2ES2().glUseProgram(id);
+ }
+ }
record.shaderId = id;
}
}
@@ -329,11 +336,11 @@ public abstract class JoglShaderUtil {
private static void enableVertexAttribute(final ShaderVariable var, final ShaderObjectsStateRecord record) {
if (!record.enabledAttributes.contains(var)) {
if (var.getSize() == 1) {
- GLContext.getCurrentGL().getGL2GL3().glEnableVertexAttribArray(var.variableID);
+ GLContext.getCurrentGL().getGL2ES2().glEnableVertexAttribArray(var.variableID);
} else {
final GL gl = GLContext.getCurrentGL();
for (int i = 0, max = var.getSize(); i < max; i++) {
- gl.getGL2GL3().glEnableVertexAttribArray(var.variableID + i);
+ gl.getGL2ES2().glEnableVertexAttribArray(var.variableID + i);
}
}
record.enabledAttributes.add(var);
@@ -349,14 +356,14 @@ public abstract class JoglShaderUtil {
JoglRendererUtil.setBoundVBO(context.getRendererRecord(), vboId);
GLContext
.getCurrentGL()
- .getGL2GL3()
+ .getGL2ES2()
.glVertexAttribPointer(variable.variableID, variable.size, GL.GL_FLOAT, variable.normalized,
variable.stride, 0);
} else {
variable.data.getBuffer().rewind();
GLContext
.getCurrentGL()
- .getGL2GL3()
+ .getGL2ES2()
.glVertexAttribPointer(variable.variableID, variable.size, GL.GL_FLOAT, variable.normalized,
variable.stride, variable.data.getBuffer());
}
@@ -375,12 +382,12 @@ public abstract class JoglShaderUtil {
if (useVBO) {
final int vboId = JoglRenderer.setupVBO(variable.data, context);
JoglRendererUtil.setBoundVBO(context.getRendererRecord(), vboId);
- gl.getGL2GL3().glVertexAttribPointer(variable.variableID + i, size, GL.GL_FLOAT, variable.normalized,
+ gl.getGL2ES2().glVertexAttribPointer(variable.variableID + i, size, GL.GL_FLOAT, variable.normalized,
0, pos);
} else {
variable.data.getBuffer().limit(pos + length - 1);
variable.data.getBuffer().position(pos);
- gl.getGL2GL3().glVertexAttribPointer(variable.variableID + i, size, GL.GL_FLOAT, variable.normalized,
+ gl.getGL2ES2().glVertexAttribPointer(variable.variableID + i, size, GL.GL_FLOAT, variable.normalized,
0, variable.data.getBuffer());
}
}
@@ -395,7 +402,7 @@ public abstract class JoglShaderUtil {
JoglRendererUtil.setBoundVBO(context.getRendererRecord(), vboId);
GLContext
.getCurrentGL()
- .getGL2GL3()
+ .getGL2ES2()
.glVertexAttribPointer(variable.variableID, variable.size,
variable.unsigned ? GL.GL_UNSIGNED_BYTE : GL.GL_BYTE, variable.normalized, variable.stride,
0);
@@ -403,7 +410,7 @@ public abstract class JoglShaderUtil {
variable.data.getBuffer().rewind();
GLContext
.getCurrentGL()
- .getGL2GL3()
+ .getGL2ES2()
.glVertexAttribPointer(variable.variableID, variable.size,
variable.unsigned ? GL.GL_UNSIGNED_BYTE : GL.GL_BYTE, variable.normalized, variable.stride,
variable.data.getBuffer());
@@ -419,7 +426,7 @@ public abstract class JoglShaderUtil {
JoglRendererUtil.setBoundVBO(context.getRendererRecord(), vboId);
GLContext
.getCurrentGL()
- .getGL2GL3()
+ .getGL2ES2()
.glVertexAttribPointer(variable.variableID, variable.size,
variable.unsigned ? GL.GL_UNSIGNED_INT : GL2ES2.GL_INT, variable.normalized,
variable.stride, 0);
@@ -427,7 +434,7 @@ public abstract class JoglShaderUtil {
variable.data.getBuffer().rewind();
GLContext
.getCurrentGL()
- .getGL2GL3()
+ .getGL2ES2()
.glVertexAttribPointer(variable.variableID, variable.size,
variable.unsigned ? GL.GL_UNSIGNED_INT : GL2ES2.GL_INT, variable.normalized,
variable.stride, variable.data.getBuffer());
@@ -443,7 +450,7 @@ public abstract class JoglShaderUtil {
JoglRendererUtil.setBoundVBO(context.getRendererRecord(), vboId);
GLContext
.getCurrentGL()
- .getGL2GL3()
+ .getGL2ES2()
.glVertexAttribPointer(variable.variableID, variable.size,
variable.unsigned ? GL.GL_UNSIGNED_SHORT : GL.GL_SHORT, variable.normalized,
variable.stride, 0);
@@ -451,7 +458,7 @@ public abstract class JoglShaderUtil {
variable.data.getBuffer().rewind();
GLContext
.getCurrentGL()
- .getGL2GL3()
+ .getGL2ES2()
.glVertexAttribPointer(variable.variableID, variable.size,
variable.unsigned ? GL.GL_UNSIGNED_SHORT : GL.GL_SHORT, variable.normalized,
variable.stride, variable.data.getBuffer());
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/util/JoglRendererUtil.java b/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/util/JoglRendererUtil.java
index 4c87387..92b416a 100644
--- a/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/util/JoglRendererUtil.java
+++ b/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/util/JoglRendererUtil.java
@@ -17,15 +17,14 @@ import javax.media.opengl.GLContext;
import com.ardor3d.math.Rectangle2;
import com.ardor3d.math.type.ReadOnlyRectangle2;
+import com.ardor3d.renderer.jogl.state.record.JoglRendererRecord;
import com.ardor3d.renderer.state.record.RendererRecord;
public abstract class JoglRendererUtil {
- public static void switchMode(final RendererRecord rendRecord, final int mode) {
- final GL gl = GLContext.getCurrentGL();
-
+ public static void switchMode(final JoglRendererRecord rendRecord, final int mode) {
if (!rendRecord.isMatrixValid() || rendRecord.getMatrixMode() != mode) {
- gl.getGL2().glMatrixMode(mode);
+ rendRecord.getMatrixBackend().setMatrixMode(mode);
rendRecord.setMatrixMode(mode);
rendRecord.setMatrixValid(true);
}
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/util/JoglTextureUtil.java b/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/util/JoglTextureUtil.java
index 2e9ab9e..e82b96d 100644
--- a/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/util/JoglTextureUtil.java
+++ b/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/util/JoglTextureUtil.java
@@ -230,6 +230,67 @@ public abstract class JoglTextureUtil {
}
}
+ public static PixelDataType getPixelDataType(final int glPixelDataType) {
+ switch (glPixelDataType) {
+ case GL.GL_BYTE:
+ return PixelDataType.Byte;
+ case GL.GL_FLOAT:
+ return PixelDataType.Float;
+ case GL.GL_HALF_FLOAT:
+ return PixelDataType.HalfFloat;
+ case GL.GL_SHORT:
+ return PixelDataType.Short;
+ case GL.GL_UNSIGNED_SHORT:
+ return PixelDataType.UnsignedShort;
+ case GL2ES2.GL_INT:
+ return PixelDataType.Int;
+ case GL.GL_UNSIGNED_INT:
+ return PixelDataType.UnsignedInt;
+ case GL.GL_UNSIGNED_BYTE:
+ return PixelDataType.UnsignedByte;
+ default:
+ throw new Error("Unhandled gl pixel data type: " + glPixelDataType);
+ }
+ }
+
+ public static ImageDataFormat getImageDataFormat(final int glPixelFormat) {
+ switch (glPixelFormat) {
+ case GL.GL_RGBA:
+ return ImageDataFormat.RGBA;
+ case GL.GL_RGB:
+ return ImageDataFormat.RGB;
+ case GL.GL_ALPHA:
+ return ImageDataFormat.Alpha;
+ case GL.GL_LUMINANCE:
+ return ImageDataFormat.Luminance;
+ case GL2.GL_INTENSITY:
+ return ImageDataFormat.Intensity;
+ case GL.GL_LUMINANCE_ALPHA:
+ return ImageDataFormat.LuminanceAlpha;
+ case GL2ES2.GL_DEPTH_COMPONENT:
+ return ImageDataFormat.Depth;
+ case GL2GL3.GL_BGR:
+ return ImageDataFormat.BGR;
+ case GL.GL_BGRA:
+ return ImageDataFormat.BGRA;
+ case GL2ES2.GL_RED:
+ return ImageDataFormat.Red;
+ case GL2GL3.GL_BLUE:
+ return ImageDataFormat.Blue;
+ case GL2GL3.GL_GREEN:
+ return ImageDataFormat.Green;
+ case GL2.GL_COLOR_INDEX:
+ return ImageDataFormat.ColorIndex;
+ case GL2ES2.GL_STENCIL_INDEX:
+ return ImageDataFormat.StencilIndex;
+ case GL2ES2.GL_RG:
+ return ImageDataFormat.RG;
+ default:
+ break;
+ }
+ throw new IllegalArgumentException("Incorrect gl pixel format set: " + glPixelFormat);
+ }
+
public static int getGLPixelFormat(final ImageDataFormat format) {
switch (format) {
case RGBA:
@@ -260,6 +321,8 @@ public abstract class JoglTextureUtil {
return GL2.GL_COLOR_INDEX;
case StencilIndex:
return GL2ES2.GL_STENCIL_INDEX;
+ case RG:
+ return GL2ES2.GL_RG;
case PrecompressedDXT1:
break;
case PrecompressedDXT1A:
@@ -272,8 +335,6 @@ public abstract class JoglTextureUtil {
break;
case PrecompressedLATC_LA:
break;
- case RG:
- break;
default:
break;
}