diff options
author | Julien Gouesse <[email protected]> | 2014-08-16 13:16:54 +0200 |
---|---|---|
committer | Julien Gouesse <[email protected]> | 2014-08-16 13:16:54 +0200 |
commit | b66a1f5f1aa26de8f32f74150f0a42f7abeb44c8 (patch) | |
tree | 74c2d445728a4d3bcef522c1565ccba800d00e02 /ardor3d-jogl/src/main/java | |
parent | 307c78940e73cead66e7003e2d4fc5c99f93f028 (diff) |
Drives the OpenGL-ES code path more robust when managing textures, blending and fog
Diffstat (limited to 'ardor3d-jogl/src/main/java')
3 files changed, 120 insertions, 41 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 e25849c..a91a125 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 @@ -743,8 +743,10 @@ public class JoglRenderer extends AbstractRenderer { gl.getGL2GL3().glEnableClientState(GLPointerFunc.GL_VERTEX_ARRAY); } vertexBuffer.rewind(); - if (gl.isGL2ES1() && vertexBufferData != null) { - gl.getGL2ES1().glVertexPointer(vertexBufferData.getValuesPerTuple(), GL.GL_FLOAT, 0, vertexBuffer); + if (vertexBufferData != null) { + if (gl.isGL2ES1()) { + gl.getGL2ES1().glVertexPointer(vertexBufferData.getValuesPerTuple(), GL.GL_FLOAT, 0, vertexBuffer); + } } } } @@ -785,8 +787,10 @@ public class JoglRenderer extends AbstractRenderer { gl.getGL2GL3().glEnableClientState(GLPointerFunc.GL_COLOR_ARRAY); } colorBuffer.rewind(); - if (gl.isGL2ES1() && colorBufferData != null) { - gl.getGL2ES1().glColorPointer(colorBufferData.getValuesPerTuple(), GL.GL_FLOAT, 0, colorBuffer); + if (colorBufferData != null) { + if (gl.isGL2ES1()) { + gl.getGL2ES1().glColorPointer(colorBufferData.getValuesPerTuple(), GL.GL_FLOAT, 0, colorBuffer); + } } } } @@ -1086,6 +1090,10 @@ public class JoglRenderer extends AbstractRenderer { JoglRendererUtil.setBoundVBO(rendRecord, vboID); if (gl.isGL2ES1()) { gl.getGL2ES1().glColorPointer(data.getValuesPerTuple(), GL.GL_FLOAT, 0, 0); + } else { + if (gl.isGL2ES2()) { + // TODO use VAO + } } } else { if (gl.isGL2GL3()) { diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglFogStateUtil.java b/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglFogStateUtil.java index bf6232b..7ed1505 100644 --- a/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglFogStateUtil.java +++ b/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglFogStateUtil.java @@ -43,23 +43,35 @@ public abstract class JoglFogStateUtil { if (record.isValid()) { if (record.fogStart != state.getStart()) { - gl.getGL2ES1().glFogf(GL2ES1.GL_FOG_START, state.getStart()); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glFogf(GL2ES1.GL_FOG_START, state.getStart()); + } record.fogStart = state.getStart(); } if (record.fogEnd != state.getEnd()) { - gl.getGL2ES1().glFogf(GL2ES1.GL_FOG_END, state.getEnd()); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glFogf(GL2ES1.GL_FOG_END, state.getEnd()); + } record.fogEnd = state.getEnd(); } if (record.density != state.getDensity()) { - gl.getGL2ES1().glFogf(GL2ES1.GL_FOG_DENSITY, state.getDensity()); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glFogf(GL2ES1.GL_FOG_DENSITY, state.getDensity()); + } record.density = state.getDensity(); } } else { - gl.getGL2ES1().glFogf(GL2ES1.GL_FOG_START, state.getStart()); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glFogf(GL2ES1.GL_FOG_START, state.getStart()); + } record.fogStart = state.getStart(); - gl.getGL2ES1().glFogf(GL2ES1.GL_FOG_END, state.getEnd()); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glFogf(GL2ES1.GL_FOG_END, state.getEnd()); + } record.fogEnd = state.getEnd(); - gl.getGL2ES1().glFogf(GL2ES1.GL_FOG_DENSITY, state.getDensity()); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glFogf(GL2ES1.GL_FOG_DENSITY, state.getDensity()); + } record.density = state.getDensity(); } @@ -107,7 +119,9 @@ public abstract class JoglFogStateUtil { record.colorBuff.put(record.fogColor.getRed()).put(record.fogColor.getGreen()) .put(record.fogColor.getBlue()).put(record.fogColor.getAlpha()); record.colorBuff.flip(); - gl.getGL2ES1().glFogfv(GL2ES1.GL_FOG_COLOR, record.colorBuff); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glFogfv(GL2ES1.GL_FOG_COLOR, record.colorBuff); + } } } 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 8d32b6e..438787d 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 @@ -927,8 +927,10 @@ public class JoglTextureStateUtil { checkAndSetUnit(unit, record, caps); checked = true; } - gl.getGL2ES1().glTexEnvf(GL2ES1.GL_TEXTURE_ENV, GL2ES1.GL_RGB_SCALE, - texture.getCombineScaleRGB().floatValue()); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexEnvf(GL2ES1.GL_TEXTURE_ENV, GL2ES1.GL_RGB_SCALE, + texture.getCombineScaleRGB().floatValue()); + } unitRecord.envRGBScale = texture.getCombineScaleRGB(); } // Then Alpha Combine scale if (!unitRecord.isValid() || unitRecord.envAlphaScale != texture.getCombineScaleAlpha()) { @@ -1121,8 +1123,10 @@ public class JoglTextureStateUtil { if (!unitRecord.isValid() || unitRecord.envMode != mode) { checkAndSetUnit(unit, record, caps); - gl.getGL2ES1().glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2ES1.GL_TEXTURE_ENV_MODE, - JoglTextureUtil.getGLEnvMode(mode)); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2ES1.GL_TEXTURE_ENV_MODE, + JoglTextureUtil.getGLEnvMode(mode)); + } unitRecord.envMode = mode; } } @@ -1138,7 +1142,10 @@ public class JoglTextureStateUtil { TextureRecord.colorBuffer.put(texBlend.getRed()).put(texBlend.getGreen()).put(texBlend.getBlue()) .put(texBlend.getAlpha()); TextureRecord.colorBuffer.rewind(); - gl.getGL2ES1().glTexEnvfv(GL2ES1.GL_TEXTURE_ENV, GL2ES1.GL_TEXTURE_ENV_COLOR, TextureRecord.colorBuffer); + if (gl.isGL2ES1()) { + gl.getGL2ES1() + .glTexEnvfv(GL2ES1.GL_TEXTURE_ENV, GL2ES1.GL_TEXTURE_ENV_COLOR, TextureRecord.colorBuffer); + } unitRecord.blendColor.set(texBlend); } } @@ -1152,7 +1159,9 @@ public class JoglTextureStateUtil { .getMaxLodBias(); if (!unitRecord.isValid() || unitRecord.lodBias != bias) { checkAndSetUnit(unit, record, caps); - gl.getGL2ES1().glTexEnvf(GL2.GL_TEXTURE_FILTER_CONTROL, GL2GL3.GL_TEXTURE_LOD_BIAS, bias); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexEnvf(GL2.GL_TEXTURE_FILTER_CONTROL, GL2GL3.GL_TEXTURE_LOD_BIAS, bias); + } unitRecord.lodBias = bias; } } @@ -1223,10 +1232,14 @@ public class JoglTextureStateUtil { if (!unitRecord.isValid() || unitRecord.textureGenSMode != GL2.GL_SPHERE_MAP) { checkAndSetUnit(unit, record, caps); - gl.getGL2ES1().glTexGeni(GL2.GL_S, GL2ES1.GL_TEXTURE_GEN_MODE, GL2.GL_SPHERE_MAP); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexGeni(GL2.GL_S, GL2ES1.GL_TEXTURE_GEN_MODE, GL2.GL_SPHERE_MAP); + } unitRecord.textureGenSMode = GL2.GL_SPHERE_MAP; - gl.getGL2ES1().glTexGeni(GL2.GL_T, GL2ES1.GL_TEXTURE_GEN_MODE, GL2.GL_SPHERE_MAP); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexGeni(GL2.GL_T, GL2ES1.GL_TEXTURE_GEN_MODE, GL2.GL_SPHERE_MAP); + } unitRecord.textureGenTMode = GL2.GL_SPHERE_MAP; } @@ -1236,13 +1249,19 @@ public class JoglTextureStateUtil { // generate normals based texture coordinates if (!unitRecord.isValid() || unitRecord.textureGenSMode != GL2ES1.GL_NORMAL_MAP) { checkAndSetUnit(unit, record, caps); - gl.getGL2ES1().glTexGeni(GL2.GL_S, GL2ES1.GL_TEXTURE_GEN_MODE, GL2ES1.GL_NORMAL_MAP); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexGeni(GL2.GL_S, GL2ES1.GL_TEXTURE_GEN_MODE, GL2ES1.GL_NORMAL_MAP); + } unitRecord.textureGenSMode = GL2ES1.GL_NORMAL_MAP; - gl.getGL2ES1().glTexGeni(GL2.GL_T, GL2ES1.GL_TEXTURE_GEN_MODE, GL2ES1.GL_NORMAL_MAP); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexGeni(GL2.GL_T, GL2ES1.GL_TEXTURE_GEN_MODE, GL2ES1.GL_NORMAL_MAP); + } unitRecord.textureGenTMode = GL2ES1.GL_NORMAL_MAP; - gl.getGL2ES1().glTexGeni(GL2.GL_R, GL2ES1.GL_TEXTURE_GEN_MODE, GL2ES1.GL_NORMAL_MAP); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexGeni(GL2.GL_R, GL2ES1.GL_TEXTURE_GEN_MODE, GL2ES1.GL_NORMAL_MAP); + } unitRecord.textureGenRMode = GL2ES1.GL_NORMAL_MAP; } @@ -1253,13 +1272,19 @@ public class JoglTextureStateUtil { if (!unitRecord.isValid() || unitRecord.textureGenSMode != GL2ES1.GL_REFLECTION_MAP) { checkAndSetUnit(unit, record, caps); - gl.getGL2ES1().glTexGeni(GL2.GL_S, GL2ES1.GL_TEXTURE_GEN_MODE, GL2ES1.GL_REFLECTION_MAP); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexGeni(GL2.GL_S, GL2ES1.GL_TEXTURE_GEN_MODE, GL2ES1.GL_REFLECTION_MAP); + } unitRecord.textureGenSMode = GL2ES1.GL_REFLECTION_MAP; - gl.getGL2ES1().glTexGeni(GL2.GL_T, GL2ES1.GL_TEXTURE_GEN_MODE, GL2ES1.GL_REFLECTION_MAP); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexGeni(GL2.GL_T, GL2ES1.GL_TEXTURE_GEN_MODE, GL2ES1.GL_REFLECTION_MAP); + } unitRecord.textureGenTMode = GL2ES1.GL_REFLECTION_MAP; - gl.getGL2ES1().glTexGeni(GL2.GL_R, GL2ES1.GL_TEXTURE_GEN_MODE, GL2ES1.GL_REFLECTION_MAP); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexGeni(GL2.GL_R, GL2ES1.GL_TEXTURE_GEN_MODE, GL2ES1.GL_REFLECTION_MAP); + } unitRecord.textureGenRMode = GL2ES1.GL_REFLECTION_MAP; } @@ -1271,27 +1296,43 @@ public class JoglTextureStateUtil { // generate eye linear texture coordinates if (!unitRecord.isValid() || unitRecord.textureGenSMode != GL2.GL_EYE_LINEAR) { - gl.getGL2ES1().glTexGeni(GL2.GL_S, GL2ES1.GL_TEXTURE_GEN_MODE, GL2.GL_EYE_LINEAR); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexGeni(GL2.GL_S, GL2ES1.GL_TEXTURE_GEN_MODE, GL2.GL_EYE_LINEAR); + } unitRecord.textureGenSMode = GL2.GL_EYE_LINEAR; - gl.getGL2ES1().glTexGeni(GL2.GL_T, GL2ES1.GL_TEXTURE_GEN_MODE, GL2.GL_EYE_LINEAR); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexGeni(GL2.GL_T, GL2ES1.GL_TEXTURE_GEN_MODE, GL2.GL_EYE_LINEAR); + } unitRecord.textureGenTMode = GL2.GL_EYE_LINEAR; - gl.getGL2ES1().glTexGeni(GL2.GL_R, GL2ES1.GL_TEXTURE_GEN_MODE, GL2.GL_EYE_LINEAR); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexGeni(GL2.GL_R, GL2ES1.GL_TEXTURE_GEN_MODE, GL2.GL_EYE_LINEAR); + } unitRecord.textureGenRMode = GL2.GL_EYE_LINEAR; - gl.getGL2ES1().glTexGeni(GL2.GL_Q, GL2ES1.GL_TEXTURE_GEN_MODE, GL2.GL_EYE_LINEAR); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexGeni(GL2.GL_Q, GL2ES1.GL_TEXTURE_GEN_MODE, GL2.GL_EYE_LINEAR); + } unitRecord.textureGenQMode = GL2.GL_EYE_LINEAR; } record.prepPlane(texture.getEnvPlaneS(), TextureStateRecord.DEFAULT_S_PLANE); - gl.getGL2ES1().glTexGenfv(GL2.GL_S, GL2.GL_EYE_PLANE, record.plane); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexGenfv(GL2.GL_S, GL2.GL_EYE_PLANE, record.plane); + } record.prepPlane(texture.getEnvPlaneT(), TextureStateRecord.DEFAULT_T_PLANE); - gl.getGL2ES1().glTexGenfv(GL2.GL_T, GL2.GL_EYE_PLANE, record.plane); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexGenfv(GL2.GL_T, GL2.GL_EYE_PLANE, record.plane); + } record.prepPlane(texture.getEnvPlaneR(), TextureStateRecord.DEFAULT_R_PLANE); - gl.getGL2ES1().glTexGenfv(GL2.GL_R, GL2.GL_EYE_PLANE, record.plane); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexGenfv(GL2.GL_R, GL2.GL_EYE_PLANE, record.plane); + } record.prepPlane(texture.getEnvPlaneQ(), TextureStateRecord.DEFAULT_Q_PLANE); - gl.getGL2ES1().glTexGenfv(GL2.GL_Q, GL2.GL_EYE_PLANE, record.plane); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexGenfv(GL2.GL_Q, GL2.GL_EYE_PLANE, record.plane); + } setTextureGen(unitRecord, unit, record, caps, true, true, true, true); break; @@ -1301,27 +1342,43 @@ public class JoglTextureStateUtil { // generate object linear texture coordinates if (!unitRecord.isValid() || unitRecord.textureGenSMode != GL2.GL_OBJECT_LINEAR) { - gl.getGL2ES1().glTexGeni(GL2.GL_S, GL2ES1.GL_TEXTURE_GEN_MODE, GL2.GL_OBJECT_LINEAR); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexGeni(GL2.GL_S, GL2ES1.GL_TEXTURE_GEN_MODE, GL2.GL_OBJECT_LINEAR); + } unitRecord.textureGenSMode = GL2.GL_OBJECT_LINEAR; - gl.getGL2ES1().glTexGeni(GL2.GL_T, GL2ES1.GL_TEXTURE_GEN_MODE, GL2.GL_OBJECT_LINEAR); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexGeni(GL2.GL_T, GL2ES1.GL_TEXTURE_GEN_MODE, GL2.GL_OBJECT_LINEAR); + } unitRecord.textureGenTMode = GL2.GL_OBJECT_LINEAR; - gl.getGL2ES1().glTexGeni(GL2.GL_R, GL2ES1.GL_TEXTURE_GEN_MODE, GL2.GL_OBJECT_LINEAR); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexGeni(GL2.GL_R, GL2ES1.GL_TEXTURE_GEN_MODE, GL2.GL_OBJECT_LINEAR); + } unitRecord.textureGenRMode = GL2.GL_OBJECT_LINEAR; - gl.getGL2ES1().glTexGeni(GL2.GL_Q, GL2ES1.GL_TEXTURE_GEN_MODE, GL2.GL_OBJECT_LINEAR); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexGeni(GL2.GL_Q, GL2ES1.GL_TEXTURE_GEN_MODE, GL2.GL_OBJECT_LINEAR); + } unitRecord.textureGenQMode = GL2.GL_OBJECT_LINEAR; } record.prepPlane(texture.getEnvPlaneS(), TextureStateRecord.DEFAULT_S_PLANE); - gl.getGL2ES1().glTexGenfv(GL2.GL_S, GL2.GL_OBJECT_PLANE, record.plane); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexGenfv(GL2.GL_S, GL2.GL_OBJECT_PLANE, record.plane); + } record.prepPlane(texture.getEnvPlaneT(), TextureStateRecord.DEFAULT_T_PLANE); - gl.getGL2ES1().glTexGenfv(GL2.GL_T, GL2.GL_OBJECT_PLANE, record.plane); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexGenfv(GL2.GL_T, GL2.GL_OBJECT_PLANE, record.plane); + } record.prepPlane(texture.getEnvPlaneR(), TextureStateRecord.DEFAULT_R_PLANE); - gl.getGL2ES1().glTexGenfv(GL2.GL_R, GL2.GL_OBJECT_PLANE, record.plane); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexGenfv(GL2.GL_R, GL2.GL_OBJECT_PLANE, record.plane); + } record.prepPlane(texture.getEnvPlaneQ(), TextureStateRecord.DEFAULT_Q_PLANE); - gl.getGL2ES1().glTexGenfv(GL2.GL_Q, GL2.GL_OBJECT_PLANE, record.plane); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexGenfv(GL2.GL_Q, GL2.GL_OBJECT_PLANE, record.plane); + } setTextureGen(unitRecord, unit, record, caps, true, true, true, true); break; |