aboutsummaryrefslogtreecommitdiffstats
path: root/ardor3d-jogl/src/main/java/com/ardor3d
diff options
context:
space:
mode:
authorJulien Gouesse <[email protected]>2013-03-01 00:51:29 +0100
committerJulien Gouesse <[email protected]>2013-03-01 00:51:29 +0100
commite567b28dd5933b8f86604f8e3db2fc75592b62bb (patch)
treedb72c32ad8ea380bc5d6d97e479fd0f2b59fe690 /ardor3d-jogl/src/main/java/com/ardor3d
parent41c1bc4f9c7921935cfc813de72ef40be9020046 (diff)
ES isolation (work in progress)
Diffstat (limited to 'ardor3d-jogl/src/main/java/com/ardor3d')
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglRenderer.java119
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglBlendStateUtil.java24
-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.java331
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/shader/JoglShaderUtil.java9
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/util/JoglRendererUtil.java6
6 files changed, 408 insertions, 94 deletions
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..c244762 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
@@ -248,15 +248,28 @@ public class JoglRenderer extends AbstractRenderer {
// set up ortho mode
final RendererRecord matRecord = ContextManager.getCurrentContext().getRendererRecord();
JoglRendererUtil.switchMode(matRecord, GLMatrixFunc.GL_PROJECTION);
- gl.getGL2().glPushMatrix();
- gl.getGL2().glLoadIdentity();
+ if (gl.isGL2ES1()) {
+ gl.getGL2ES1().glPushMatrix();
+ gl.getGL2ES1().glLoadIdentity();
+ } else {
+ // TODO use PMVMatrix
+ }
+
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);
+ if (gl.isGL2ES1()) {
+ gl.getGL2ES1().glOrtho(0, viewportWidth, 0, viewportHeight, -1, 1);
+ } else {
+ // TODO use PMVMatrix
+ }
JoglRendererUtil.switchMode(matRecord, GLMatrixFunc.GL_MODELVIEW);
- gl.getGL2().glPushMatrix();
- gl.getGL2().glLoadIdentity();
+ if (gl.isGL2ES1()) {
+ gl.getGL2ES1().glPushMatrix();
+ gl.getGL2ES1().glLoadIdentity();
+ } else {
+ // TODO use PMVMatrix
+ }
_inOrthoMode = true;
}
@@ -270,9 +283,17 @@ public class JoglRenderer extends AbstractRenderer {
// state
final RendererRecord matRecord = ContextManager.getCurrentContext().getRendererRecord();
JoglRendererUtil.switchMode(matRecord, GLMatrixFunc.GL_PROJECTION);
- gl.getGL2().glPopMatrix();
+ if (gl.isGL2ES1()) {
+ gl.getGL2ES1().glPopMatrix();
+ } else {
+ // TODO use PMVMatrix
+ }
JoglRendererUtil.switchMode(matRecord, GLMatrixFunc.GL_MODELVIEW);
- gl.getGL2().glPopMatrix();
+ if (gl.isGL2ES1()) {
+ gl.getGL2ES1().glPopMatrix();
+ } else {
+ // TODO use PMVMatrix
+ }
_inOrthoMode = false;
}
@@ -405,10 +426,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);
}
}
@@ -654,8 +675,12 @@ public class JoglRenderer extends AbstractRenderer {
final RendererRecord matRecord = ContextManager.getCurrentContext().getRendererRecord();
JoglRendererUtil.switchMode(matRecord, GLMatrixFunc.GL_MODELVIEW);
- gl.getGL2().glPushMatrix();
- gl.getGL2().glMultMatrixf(_transformBuffer);
+ if (gl.isGL2ES1()) {
+ gl.getGL2ES1().glPushMatrix();
+ gl.getGL2ES1().glMultMatrixf(_transformBuffer);
+ } else {
+ // TODO use PMVMatrix
+ }
return true;
}
}
@@ -667,7 +692,11 @@ public class JoglRenderer extends AbstractRenderer {
final RendererRecord matRecord = ContextManager.getCurrentContext().getRendererRecord();
JoglRendererUtil.switchMode(matRecord, GLMatrixFunc.GL_MODELVIEW);
- gl.getGL2().glPopMatrix();
+ if (gl.isGL2ES1()) {
+ gl.getGL2ES1().glPopMatrix();
+ } else {
+ // TODO use PMVMatrix
+ }
}
public void setupVertexData(final FloatBufferData vertexBufferData) {
@@ -680,7 +709,9 @@ public class JoglRenderer extends AbstractRenderer {
} else {
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);
+ }
}
}
@@ -694,7 +725,9 @@ public class JoglRenderer extends AbstractRenderer {
} else {
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);
+ }
}
}
@@ -708,7 +741,9 @@ public class JoglRenderer extends AbstractRenderer {
} else {
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);
+ }
}
}
@@ -722,7 +757,9 @@ public class JoglRenderer extends AbstractRenderer {
} else {
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);
+ }
}
}
@@ -775,7 +812,10 @@ public class JoglRenderer extends AbstractRenderer {
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);
+ }
}
}
}
@@ -931,7 +971,9 @@ public class JoglRenderer extends AbstractRenderer {
if (vboID != 0) {
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);
}
@@ -948,7 +990,9 @@ public class JoglRenderer extends AbstractRenderer {
if (vboID != 0) {
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);
}
@@ -965,7 +1009,9 @@ public class JoglRenderer extends AbstractRenderer {
if (vboID != 0) {
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);
}
@@ -987,7 +1033,9 @@ public class JoglRenderer extends AbstractRenderer {
if (vboID != 0) {
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);
}
@@ -1046,7 +1094,9 @@ public class JoglRenderer extends AbstractRenderer {
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 {
@@ -1095,7 +1145,9 @@ public class JoglRenderer extends AbstractRenderer {
if (normalCoords != null) {
updateVBO(normalCoords, rendRecord, vboID, offsetBytes);
- gl.getGL2().glNormalPointer(GL.GL_FLOAT, 0, offsetBytes);
+ if (gl.isGL2ES1()) {
+ gl.getGL2ES1().glNormalPointer(GL.GL_FLOAT, 0, offsetBytes);
+ }
gl.getGL2GL3().glEnableClientState(GLPointerFunc.GL_NORMAL_ARRAY);
offsetBytes += normalCoords.getBufferLimit() * 4;
} else {
@@ -1104,7 +1156,9 @@ public class JoglRenderer extends AbstractRenderer {
if (colorCoords != null) {
updateVBO(colorCoords, rendRecord, vboID, offsetBytes);
- gl.getGL2().glColorPointer(colorCoords.getValuesPerTuple(), GL.GL_FLOAT, 0, offsetBytes);
+ if (gl.isGL2ES1()) {
+ gl.getGL2ES1().glColorPointer(colorCoords.getValuesPerTuple(), GL.GL_FLOAT, 0, offsetBytes);
+ }
gl.getGL2GL3().glEnableClientState(GLPointerFunc.GL_COLOR_ARRAY);
offsetBytes += colorCoords.getBufferLimit() * 4;
} else {
@@ -1155,8 +1209,10 @@ public class JoglRenderer extends AbstractRenderer {
}
// 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,7 +1224,9 @@ public class JoglRenderer extends AbstractRenderer {
if (vertexCoords != null) {
updateVBO(vertexCoords, rendRecord, vboID, offsetBytes);
- gl.getGL2().glVertexPointer(vertexCoords.getValuesPerTuple(), GL.GL_FLOAT, 0, offsetBytes);
+ if (gl.isGL2ES1()) {
+ gl.getGL2ES1().glVertexPointer(vertexCoords.getValuesPerTuple(), GL.GL_FLOAT, 0, offsetBytes);
+ }
gl.getGL2GL3().glEnableClientState(GLPointerFunc.GL_VERTEX_ARRAY);
} else {
gl.getGL2GL3().glDisableClientState(GLPointerFunc.GL_VERTEX_ARRAY);
@@ -1451,7 +1509,12 @@ public class JoglRenderer extends AbstractRenderer {
}
private void loadMatrix(final FloatBuffer matrix) {
- GLContext.getCurrentGL().getGL2().glLoadMatrixf(matrix);
+ final GL gl = GLContext.getCurrentGL();
+ if (gl.isGL2ES1()) {
+ gl.getGL2ES1().glLoadMatrixf(matrix);
+ } else {
+ // TODO use PMVMatrix
+ }
}
public FloatBuffer getModelViewMatrix(final FloatBuffer store) {
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..30c86e4 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
@@ -372,30 +372,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..d07836e 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);
+ // TODO replace glGetObjectParameterivARB
+ }
+ }
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);
+ // TODO replace glGetObjectParameterivARB
+ }
+ }
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);
+ // TODO replace glGetObjectParameterivARB
+ }
+ }
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,51 @@ 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);
+ // TODO replace lGetObjectParameterivARB
+ }
+ }
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 +278,66 @@ 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);
+ // TODO replace glGetObjectParameterivARB
+ }
+ }
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 +347,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()) {
+ // TODO replace glGetObjectParameterivARB
+ }
+ }
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()) {
+ // TODO replace glGetObjectParameterivARB
+ }
+ }
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()) {
+ // TODO replace glGetInfoLogARB
+ }
+ }
final byte[] infoBytes = new byte[length];
infoLog.get(infoBytes);
@@ -227,8 +390,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 +407,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 +424,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 +441,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 +458,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 +483,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()) {
+ // TODO glGetObjectParameterivARB
+ }
+ }
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()) {
+ // TODO glGetInfoLogARB
+ }
+ }
final byte[] infoBytes = new byte[length];
infoLog.get(infoBytes);
@@ -374,10 +583,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/shader/JoglShaderUtil.java b/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/shader/JoglShaderUtil.java
index 006cdb8..0375e69 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
@@ -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;
}
}
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..ff3df27 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
@@ -25,7 +25,11 @@ public abstract class JoglRendererUtil {
final GL gl = GLContext.getCurrentGL();
if (!rendRecord.isMatrixValid() || rendRecord.getMatrixMode() != mode) {
- gl.getGL2().glMatrixMode(mode);
+ if (gl.isGL2ES1()) {
+ gl.getGL2ES1().glMatrixMode(mode);
+ } else {
+ // TODO use PMVMatrix
+ }
rendRecord.setMatrixMode(mode);
rendRecord.setMatrixValid(true);
}