diff options
Diffstat (limited to 'ardor3d-jogl/src/main/java')
10 files changed, 469 insertions, 248 deletions
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglContextCapabilities.java b/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglContextCapabilities.java index 5ee1cb8..b83176a 100644 --- a/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglContextCapabilities.java +++ b/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglContextCapabilities.java @@ -67,8 +67,10 @@ public class JoglContextCapabilities extends ContextCapabilities { _maxTextureLodBias = 0f; } - gl.glGetIntegerv(GL2ES1.GL_MAX_CLIP_PLANES, buf); - _maxUserClipPlanes = buf.get(0); + if (gl.isGL2ES1()) { + gl.glGetIntegerv(GL2ES1.GL_MAX_CLIP_PLANES, buf); + _maxUserClipPlanes = buf.get(0); + } _glslSupported = gl.isExtensionAvailable("GL_ARB_shader_objects") && gl.isExtensionAvailable("GL_ARB_fragment_shader") && gl.isExtensionAvailable("GL_ARB_vertex_shader") @@ -82,8 +84,12 @@ public class JoglContextCapabilities extends ContextCapabilities { _tessellationShadersSupported = gl.isExtensionAvailable("GL_ARB_tessellation_shader") && _glslSupported; if (_glslSupported) { - gl.glGetIntegerv(GL2.GL_MAX_VERTEX_ATTRIBS_ARB, buf); - _maxGLSLVertexAttribs = buf.get(0); + if (gl.isGL2()) { + gl.glGetIntegerv(GL2.GL_MAX_VERTEX_ATTRIBS_ARB, buf); + _maxGLSLVertexAttribs = buf.get(0); + } else { + // FIXME use a reasonable value + } } // Pbuffer @@ -96,7 +102,7 @@ public class JoglContextCapabilities extends ContextCapabilities { _supportsFBOMultisample = gl.isExtensionAvailable("GL_EXT_framebuffer_multisample"); _supportsFBOBlit = gl.isExtensionAvailable("GL_EXT_framebuffer_blit"); - if (gl.isExtensionAvailable("GL_ARB_draw_buffers")) { + if (gl.isExtensionAvailable("GL_ARB_draw_buffers") && gl.isGL2ES2()) { gl.glGetIntegerv(GL2ES2.GL_MAX_COLOR_ATTACHMENTS, buf); _maxFBOColorAttachments = buf.get(0); } else { @@ -105,7 +111,7 @@ public class JoglContextCapabilities extends ContextCapabilities { // Max multisample samples. if (gl.isExtensionAvailable("GL_EXT_framebuffer_multisample") - && gl.isExtensionAvailable("GL_EXT_framebuffer_blit")) { + && gl.isExtensionAvailable("GL_EXT_framebuffer_blit") && gl.isGL2ES3()) { gl.glGetIntegerv(GL2ES3.GL_MAX_SAMPLES, buf); _maxFBOSamples = buf.get(0); } else { @@ -119,8 +125,10 @@ public class JoglContextCapabilities extends ContextCapabilities { _stencilWrapSupport = gl.isExtensionAvailable("GL_EXT_stencil_wrap"); // number of available auxiliary draw buffers - gl.glGetIntegerv(GL2.GL_AUX_BUFFERS, buf); - _numAuxDrawBuffers = buf.get(0); + if (gl.isGL2()) { + gl.glGetIntegerv(GL2.GL_AUX_BUFFERS, buf); + _numAuxDrawBuffers = buf.get(0); + } // max texture size. gl.glGetIntegerv(GL.GL_MAX_TEXTURE_SIZE, buf); @@ -148,9 +156,10 @@ public class JoglContextCapabilities extends ContextCapabilities { // If we do support multitexturing, find out how many textures we // can handle. - if (_supportsMultiTexture) { + if (_supportsMultiTexture && gl.isGL2ES1()) { gl.glGetIntegerv(GL2ES1.GL_MAX_TEXTURE_UNITS, buf); _numFixedTexUnits = buf.get(0); + // FIXME use a reasonable value when ES2 & 3 are detected } else { _numFixedTexUnits = 1; } @@ -241,14 +250,18 @@ public class JoglContextCapabilities extends ContextCapabilities { _displayVersion = "Unable to retrieve API version."; } - if (_glslSupported) { - try { - _shadingLanguageVersion = gl.glGetString(GL2ES2.GL_SHADING_LANGUAGE_VERSION); - } catch (final Exception e) { - _shadingLanguageVersion = "Unable to retrieve shading language version."; - } - } else { + if (gl.isGLES1()) { _shadingLanguageVersion = "Not supported."; + } else { + if (_glslSupported) { + try { + _shadingLanguageVersion = gl.glGetString(GL2ES2.GL_SHADING_LANGUAGE_VERSION); + } catch (final Exception e) { + _shadingLanguageVersion = "Unable to retrieve shading language version."; + } + } else { + _shadingLanguageVersion = "Not supported."; + } } } } 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 a91a125..206c188 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 @@ -628,12 +628,16 @@ public class JoglRenderer extends AbstractRenderer { GL.GL_UNSIGNED_BYTE, source); break; case OneDimensional: - gl.getGL2GL3().glTexSubImage1D(GL2GL3.GL_TEXTURE_1D, 0, dstOffsetX, dstWidth, pixelFormat, - GL.GL_UNSIGNED_BYTE, source); + if (gl.isGL2GL3()) { + gl.getGL2GL3().glTexSubImage1D(GL2GL3.GL_TEXTURE_1D, 0, dstOffsetX, dstWidth, pixelFormat, + GL.GL_UNSIGNED_BYTE, source); + } break; case ThreeDimensional: - gl.getGL2ES2().glTexSubImage3D(GL2ES2.GL_TEXTURE_3D, 0, dstOffsetX, dstOffsetY, dstOffsetZ, - dstWidth, dstHeight, dstDepth, pixelFormat, GL.GL_UNSIGNED_BYTE, source); + if (gl.isGL2ES2()) { + gl.getGL2ES2().glTexSubImage3D(GL2ES2.GL_TEXTURE_3D, 0, dstOffsetX, dstOffsetY, dstOffsetZ, + dstWidth, dstHeight, dstDepth, pixelFormat, GL.GL_UNSIGNED_BYTE, source); + } break; case CubeMap: gl.glTexSubImage2D(JoglTextureStateUtil.getGLCubeMapFace(dstFace), 0, dstOffsetX, dstOffsetY, diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglTextureRenderer.java b/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglTextureRenderer.java index 4b24580..532880c 100644 --- a/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglTextureRenderer.java +++ b/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglTextureRenderer.java @@ -106,7 +106,10 @@ public class JoglTextureRenderer extends AbstractFBOTextureRenderer { // Initialize mipmapping for this texture, if requested if (tex.getMinificationFilter().usesMipMapLevels()) { - gl.glGenerateMipmap(JoglTextureStateUtil.getGLType(tex.getType())); + final int glType = JoglTextureStateUtil.getGLType(tex.getType()); + if (glType != GL.GL_INVALID_ENUM) { + gl.glGenerateMipmap(glType); + } } // Setup filtering and wrap @@ -252,7 +255,10 @@ public class JoglTextureRenderer extends AbstractFBOTextureRenderer { final Texture tex = texs.get(x); if (tex.getMinificationFilter().usesMipMapLevels()) { JoglTextureStateUtil.doTextureBind(tex, 0, true); - gl.glGenerateMipmap(JoglTextureStateUtil.getGLType(tex.getType())); + final int glType = JoglTextureStateUtil.getGLType(tex.getType()); + if (glType != GL.GL_INVALID_ENUM) { + gl.glGenerateMipmap(glType); + } } } } finally { @@ -351,7 +357,10 @@ public class JoglTextureRenderer extends AbstractFBOTextureRenderer { // automatically generate mipmaps for our texture. if (tex.getMinificationFilter().usesMipMapLevels()) { JoglTextureStateUtil.doTextureBind(tex, 0, true); - gl.glGenerateMipmap(JoglTextureStateUtil.getGLType(tex.getType())); + final int glType = JoglTextureStateUtil.getGLType(tex.getType()); + if (glType != GL.GL_INVALID_ENUM) { + gl.glGenerateMipmap(JoglTextureStateUtil.getGLType(tex.getType())); + } } } 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 7ed1505..4363aec 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 @@ -94,17 +94,25 @@ public abstract class JoglFogStateUtil { if (record.isValid()) { if (enable && !record.enabled) { - gl.glEnable(GL2ES1.GL_FOG); + if (gl.isGL2ES1()) { + gl.glEnable(GL2ES1.GL_FOG); + } record.enabled = true; } else if (!enable && record.enabled) { - gl.glDisable(GL2ES1.GL_FOG); + if (gl.isGL2ES1()) { + gl.glDisable(GL2ES1.GL_FOG); + } record.enabled = false; } } else { if (enable) { - gl.glEnable(GL2ES1.GL_FOG); + if (gl.isGL2ES1()) { + gl.glEnable(GL2ES1.GL_FOG); + } } else { - gl.glDisable(GL2ES1.GL_FOG); + if (gl.isGL2ES1()) { + gl.glDisable(GL2ES1.GL_FOG); + } } record.enabled = enable; } @@ -182,7 +190,9 @@ public abstract class JoglFogStateUtil { } if (!record.isValid() || record.fogHint != glHint) { - gl.glHint(GL2ES1.GL_FOG_HINT, glHint); + if (gl.isGL2ES1()) { + gl.glHint(GL2ES1.GL_FOG_HINT, glHint); + } record.fogHint = glHint; } } diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglLightStateUtil.java b/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglLightStateUtil.java index f5f8bf3..27daf9e 100644 --- a/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglLightStateUtil.java +++ b/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglLightStateUtil.java @@ -167,9 +167,13 @@ public abstract class JoglLightStateUtil { if (!record.isValid() || lr.isEnabled() != enable) { if (enable) { - gl.glEnable(GLLightingFunc.GL_LIGHT0 + index); + if (gl.isGL2ES1()) { + gl.glEnable(GLLightingFunc.GL_LIGHT0 + index); + } } else { - gl.glDisable(GLLightingFunc.GL_LIGHT0 + index); + if (gl.isGL2ES1()) { + gl.glDisable(GLLightingFunc.GL_LIGHT0 + index); + } } lr.setEnabled(enable); @@ -181,9 +185,13 @@ public abstract class JoglLightStateUtil { if (!record.isValid() || record.isEnabled() != enable) { if (enable) { - gl.glEnable(GLLightingFunc.GL_LIGHTING); + if (gl.isGL2ES1()) { + gl.glEnable(GLLightingFunc.GL_LIGHTING); + } } else { - gl.glDisable(GLLightingFunc.GL_LIGHTING); + if (gl.isGL2ES1()) { + gl.glDisable(GLLightingFunc.GL_LIGHTING); + } } record.setEnabled(enable); } diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglMaterialStateUtil.java b/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglMaterialStateUtil.java index d9a6e58..251eb45 100644 --- a/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglMaterialStateUtil.java +++ b/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglMaterialStateUtil.java @@ -142,14 +142,18 @@ public abstract class JoglMaterialStateUtil { final GL gl = GLContext.getCurrentGL(); if (colorMaterial == ColorMaterial.None) { - gl.glDisable(GLLightingFunc.GL_COLOR_MATERIAL); + if (gl.isGL2()) { + gl.glDisable(GLLightingFunc.GL_COLOR_MATERIAL); + } } else { final int glMat = getGLColorMaterial(colorMaterial); final int glFace = getGLMaterialFace(face); if (gl.isGL2()) { gl.getGL2().glColorMaterial(glFace, glMat); } - gl.glEnable(GLLightingFunc.GL_COLOR_MATERIAL); + if (gl.isGL2()) { + gl.glEnable(GLLightingFunc.GL_COLOR_MATERIAL); + } record.resetColorsForCM(face, colorMaterial); } record.colorMaterial = colorMaterial; diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglOffsetStateUtil.java b/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglOffsetStateUtil.java index ec48484..5711504 100644 --- a/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglOffsetStateUtil.java +++ b/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglOffsetStateUtil.java @@ -59,10 +59,12 @@ public abstract class JoglOffsetStateUtil { final int glType = getGLType(type); if (!record.isValid() || typeEnabled != record.enabledOffsets.contains(type)) { - if (typeEnabled) { - gl.glEnable(glType); - } else { - gl.glDisable(glType); + if (!gl.isGLES()) { + if (typeEnabled) { + gl.glEnable(glType); + } else { + gl.glDisable(glType); + } } } } 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 438787d..ecf09f9 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 @@ -230,10 +230,13 @@ public class JoglTextureStateUtil { // ensure the buffer is ready for reading image.getData(0).rewind(); // send top level to card - gl.getGL2GL3().glTexImage1D(GL2GL3.GL_TEXTURE_1D, 0, - JoglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()), image.getWidth(), - hasBorder ? 1 : 0, JoglTextureUtil.getGLPixelFormat(image.getDataFormat()), - JoglTextureUtil.getGLPixelDataType(image.getDataType()), image.getData(0)); + if (gl.isGL2GL3()) { + gl.getGL2GL3().glTexImage1D(GL2GL3.GL_TEXTURE_1D, 0, + JoglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()), + image.getWidth(), hasBorder ? 1 : 0, + JoglTextureUtil.getGLPixelFormat(image.getDataFormat()), + JoglTextureUtil.getGLPixelDataType(image.getDataType()), image.getData(0)); + } break; case ThreeDimensional: if (caps.isTexture3DSupported()) { @@ -303,7 +306,12 @@ public class JoglTextureStateUtil { if (caps.isAutomaticMipmapsSupported()) { // Flag the card to generate mipmaps - gl.glTexParameteri(getGLType(type), GL2ES1.GL_GENERATE_MIPMAP, GL.GL_TRUE); + if (gl.isGL2ES1()) { + final int glType = getGLType(texture.getType()); + if (glType != GL.GL_INVALID_ENUM) { + gl.glTexParameteri(glType, GL2ES1.GL_GENERATE_MIPMAP, GL.GL_TRUE); + } + } } switch (type) { @@ -319,19 +327,13 @@ public class JoglTextureStateUtil { JoglTextureUtil.getGLPixelDataType(image.getDataType()), image.getData(0)); } else { // FIXME workaround for the bug 1045: https://jogamp.org/bugzilla/show_bug.cgi?id=1045 - if (gl.isGL2() || gl.isGL2ES1()) { + if (gl.isGL2() /* || gl.isGL2ES1() */) { // send to card glu.gluBuild2DMipmaps(GL.GL_TEXTURE_2D, JoglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()), image.getWidth(), image.getHeight(), JoglTextureUtil.getGLPixelFormat(image.getDataFormat()), JoglTextureUtil.getGLPixelDataType(image.getDataType()), image.getData(0)); - } else { - gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, - JoglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()), - image.getWidth(), image.getHeight(), hasBorder ? 1 : 0, - JoglTextureUtil.getGLPixelFormat(image.getDataFormat()), - JoglTextureUtil.getGLPixelDataType(image.getDataType()), image.getData(0)); } } break; @@ -340,11 +342,13 @@ public class JoglTextureStateUtil { image.getData(0).rewind(); if (caps.isAutomaticMipmapsSupported()) { // send top level to card - gl.getGL2GL3().glTexImage1D(GL2GL3.GL_TEXTURE_1D, 0, - JoglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()), - image.getWidth(), hasBorder ? 1 : 0, - JoglTextureUtil.getGLPixelFormat(image.getDataFormat()), - JoglTextureUtil.getGLPixelDataType(image.getDataType()), image.getData(0)); + if (gl.isGL2GL3()) { + gl.getGL2GL3().glTexImage1D(GL2GL3.GL_TEXTURE_1D, 0, + JoglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()), + image.getWidth(), hasBorder ? 1 : 0, + JoglTextureUtil.getGLPixelFormat(image.getDataFormat()), + JoglTextureUtil.getGLPixelDataType(image.getDataType()), image.getData(0)); + } } else { // Note: JOGL's GLU class does not support // gluBuild1DMipmaps. @@ -413,7 +417,7 @@ public class JoglTextureStateUtil { } } else { // FIXME workaround for the bug 1045: https://jogamp.org/bugzilla/show_bug.cgi?id=1045 - if (gl.isGL2() || gl.isGL2ES1()) { + if (gl.isGL2() /* || gl.isGL2ES1() */) { for (final TextureCubeMap.Face face : TextureCubeMap.Face.values()) { // ensure the buffer is ready for reading image.getData(face.ordinal()).rewind(); @@ -425,18 +429,6 @@ public class JoglTextureStateUtil { JoglTextureUtil.getGLPixelDataType(image.getDataType()), image.getData(face.ordinal())); } - } else { - for (final TextureCubeMap.Face face : TextureCubeMap.Face.values()) { - // ensure the buffer is ready for reading - image.getData(face.ordinal()).rewind(); - // send top level to card - gl.glTexImage2D(getGLCubeMapFace(face), 0, - JoglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()), - image.getWidth(), image.getWidth(), hasBorder ? 1 : 0, - JoglTextureUtil.getGLPixelFormat(image.getDataFormat()), - JoglTextureUtil.getGLPixelDataType(image.getDataType()), - image.getData(face.ordinal())); - } } } } else { @@ -519,10 +511,14 @@ public class JoglTextureStateUtil { gl.glTexParameteri(GL.GL_TEXTURE_2D, GL2ES3.GL_TEXTURE_MAX_LEVEL, max - 1); break; case ThreeDimensional: - gl.glTexParameteri(GL2ES2.GL_TEXTURE_3D, GL2ES3.GL_TEXTURE_MAX_LEVEL, max - 1); + if (gl.isGL2ES2()) { + gl.glTexParameteri(GL2ES2.GL_TEXTURE_3D, GL2ES3.GL_TEXTURE_MAX_LEVEL, max - 1); + } break; case OneDimensional: - gl.glTexParameteri(GL2GL3.GL_TEXTURE_1D, GL2ES3.GL_TEXTURE_MAX_LEVEL, max - 1); + if (gl.isGL2GL3()) { + gl.glTexParameteri(GL2GL3.GL_TEXTURE_1D, GL2ES3.GL_TEXTURE_MAX_LEVEL, max - 1); + } break; case CubeMap: break; @@ -584,30 +580,38 @@ public class JoglTextureStateUtil { break; case OneDimensional: if (texture.getTextureStoreFormat().isCompressed()) { - gl.getGL2GL3().glCompressedTexImage1D(GL2GL3.GL_TEXTURE_1D, m, - JoglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()), - width, hasBorder ? 1 : 0, mipSizes[m], data); + if (gl.isGL2GL3()) { + gl.getGL2GL3().glCompressedTexImage1D(GL2GL3.GL_TEXTURE_1D, m, + JoglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()), + width, hasBorder ? 1 : 0, mipSizes[m], data); + } } else { - gl.getGL2GL3().glTexImage1D(GL2GL3.GL_TEXTURE_1D, m, - JoglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()), - width, hasBorder ? 1 : 0, - JoglTextureUtil.getGLPixelFormat(image.getDataFormat()), - JoglTextureUtil.getGLPixelDataType(image.getDataType()), data); + if (gl.isGL2GL3()) { + gl.getGL2GL3().glTexImage1D(GL2GL3.GL_TEXTURE_1D, m, + JoglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()), + width, hasBorder ? 1 : 0, + JoglTextureUtil.getGLPixelFormat(image.getDataFormat()), + JoglTextureUtil.getGLPixelDataType(image.getDataType()), data); + } } break; case ThreeDimensional: final int depth = Math.max(1, image.getDepth() >> m); // already checked for support above... if (texture.getTextureStoreFormat().isCompressed()) { - gl.getGL2ES2().glCompressedTexImage3D(GL2ES2.GL_TEXTURE_3D, m, - JoglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()), - width, height, depth, hasBorder ? 1 : 0, mipSizes[m], data); + if (gl.isGL2ES2()) { + gl.getGL2ES2().glCompressedTexImage3D(GL2ES2.GL_TEXTURE_3D, m, + JoglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()), + width, height, depth, hasBorder ? 1 : 0, mipSizes[m], data); + } } else { - gl.getGL2ES2().glTexImage3D(GL2ES2.GL_TEXTURE_3D, m, - JoglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()), - width, height, depth, hasBorder ? 1 : 0, - JoglTextureUtil.getGLPixelFormat(image.getDataFormat()), - JoglTextureUtil.getGLPixelDataType(image.getDataType()), data); + if (gl.isGL2ES2()) { + gl.getGL2ES2().glTexImage3D(GL2ES2.GL_TEXTURE_3D, m, + JoglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()), + width, height, depth, hasBorder ? 1 : 0, + JoglTextureUtil.getGLPixelFormat(image.getDataFormat()), + JoglTextureUtil.getGLPixelDataType(image.getDataType()), data); + } } break; case CubeMap: @@ -647,7 +651,9 @@ public class JoglTextureStateUtil { final int glHint = JoglTextureUtil.getPerspHint(state.getCorrectionType()); if (!record.isValid() || record.hint != glHint) { // set up correction mode - gl.glHint(GL2ES1.GL_PERSPECTIVE_CORRECTION_HINT, glHint); + if (gl.isGL2ES1()) { + gl.glHint(GL2ES1.GL_PERSPECTIVE_CORRECTION_HINT, glHint); + } record.hint = glHint; } @@ -714,7 +720,10 @@ public class JoglTextureStateUtil { // texture already exists in OpenGL, just bind it if needed if (!unitRecord.isValid() || unitRecord.boundTexture != textureId || fbo) { checkAndSetUnit(i, record, caps); - gl.glBindTexture(getGLType(type), textureId); + final int glType = getGLType(type); + if (glType != GL.GL_INVALID_ENUM) { + gl.glBindTexture(glType, textureId); + } if (Constants.stats) { StatCollector.addStat(StatType.STAT_TEXTURE_BINDS, 1); } @@ -741,7 +750,12 @@ public class JoglTextureStateUtil { // Enable 2D texturing on this unit if not enabled. if (!unitRecord.isValid() || !unitRecord.enabled[type.ordinal()]) { checkAndSetUnit(i, record, caps); - gl.glEnable(getGLType(type)); + final int glType = getGLType(type); + if (glType != GL.GL_INVALID_ENUM) { + if (!gl.isGLES2()) { + gl.glEnable(glType); + } + } unitRecord.enabled[type.ordinal()] = true; } @@ -834,7 +848,9 @@ public class JoglTextureStateUtil { if (!unitRecord.isValid() || unitRecord.enabled[Type.OneDimensional.ordinal()]) { // Check we are in the right unit checkAndSetUnit(unit, record, caps); - gl.glDisable(GL2GL3.GL_TEXTURE_1D); + if (gl.isGL2GL3()) { + gl.glDisable(GL2GL3.GL_TEXTURE_1D); + } unitRecord.enabled[Type.OneDimensional.ordinal()] = false; } } @@ -873,7 +889,9 @@ public class JoglTextureStateUtil { if (!unitRecord.isValid() || unitRecord.enabled[Type.OneDimensional.ordinal()]) { // Check we are in the right unit checkAndSetUnit(unit, record, caps); - gl.glDisable(GL2GL3.GL_TEXTURE_1D); + if (gl.isGL2GL3()) { + gl.glDisable(GL2GL3.GL_TEXTURE_1D); + } unitRecord.enabled[Type.OneDimensional.ordinal()] = false; } @@ -938,8 +956,10 @@ public class JoglTextureStateUtil { checkAndSetUnit(unit, record, caps); checked = true; } - gl.getGL2ES1().glTexEnvf(GL2ES1.GL_TEXTURE_ENV, GL2ES1.GL_ALPHA_SCALE, - texture.getCombineScaleAlpha().floatValue()); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexEnvf(GL2ES1.GL_TEXTURE_ENV, GL2ES1.GL_ALPHA_SCALE, + texture.getCombineScaleAlpha().floatValue()); + } unitRecord.envAlphaScale = texture.getCombineScaleAlpha(); } @@ -950,8 +970,10 @@ public class JoglTextureStateUtil { checkAndSetUnit(unit, record, caps); checked = true; } - gl.getGL2ES1().glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2ES1.GL_COMBINE_RGB, - JoglTextureUtil.getGLCombineFuncRGB(rgbCombineFunc)); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2ES1.GL_COMBINE_RGB, + JoglTextureUtil.getGLCombineFuncRGB(rgbCombineFunc)); + } unitRecord.rgbCombineFunc = rgbCombineFunc; } @@ -961,8 +983,10 @@ public class JoglTextureStateUtil { checkAndSetUnit(unit, record, caps); checked = true; } - gl.getGL2ES1().glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2.GL_SOURCE0_RGB, - JoglTextureUtil.getGLCombineSrc(combSrcRGB)); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2.GL_SOURCE0_RGB, + JoglTextureUtil.getGLCombineSrc(combSrcRGB)); + } unitRecord.combSrcRGB0 = combSrcRGB; } @@ -972,8 +996,10 @@ public class JoglTextureStateUtil { checkAndSetUnit(unit, record, caps); checked = true; } - gl.getGL2ES1().glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2ES1.GL_OPERAND0_RGB, - JoglTextureUtil.getGLCombineOpRGB(combOpRGB)); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2ES1.GL_OPERAND0_RGB, + JoglTextureUtil.getGLCombineOpRGB(combOpRGB)); + } unitRecord.combOpRGB0 = combOpRGB; } @@ -986,8 +1012,10 @@ public class JoglTextureStateUtil { checkAndSetUnit(unit, record, caps); checked = true; } - gl.getGL2ES1().glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2.GL_SOURCE1_RGB, - JoglTextureUtil.getGLCombineSrc(combSrcRGB)); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2.GL_SOURCE1_RGB, + JoglTextureUtil.getGLCombineSrc(combSrcRGB)); + } unitRecord.combSrcRGB1 = combSrcRGB; } @@ -997,8 +1025,10 @@ public class JoglTextureStateUtil { checkAndSetUnit(unit, record, caps); checked = true; } - gl.getGL2ES1().glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2ES1.GL_OPERAND1_RGB, - JoglTextureUtil.getGLCombineOpRGB(combOpRGB)); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2ES1.GL_OPERAND1_RGB, + JoglTextureUtil.getGLCombineOpRGB(combOpRGB)); + } unitRecord.combOpRGB1 = combOpRGB; } @@ -1011,8 +1041,10 @@ public class JoglTextureStateUtil { checkAndSetUnit(unit, record, caps); checked = true; } - gl.getGL2ES1().glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2.GL_SOURCE2_RGB, - JoglTextureUtil.getGLCombineSrc(combSrcRGB)); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2.GL_SOURCE2_RGB, + JoglTextureUtil.getGLCombineSrc(combSrcRGB)); + } unitRecord.combSrcRGB2 = combSrcRGB; } @@ -1022,8 +1054,10 @@ public class JoglTextureStateUtil { checkAndSetUnit(unit, record, caps); checked = true; } - gl.getGL2ES1().glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2ES1.GL_OPERAND2_RGB, - JoglTextureUtil.getGLCombineOpRGB(combOpRGB)); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2ES1.GL_OPERAND2_RGB, + JoglTextureUtil.getGLCombineOpRGB(combOpRGB)); + } unitRecord.combOpRGB2 = combOpRGB; } @@ -1037,8 +1071,10 @@ public class JoglTextureStateUtil { checkAndSetUnit(unit, record, caps); checked = true; } - gl.getGL2ES1().glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2ES1.GL_COMBINE_ALPHA, - JoglTextureUtil.getGLCombineFuncAlpha(alphaCombineFunc)); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2ES1.GL_COMBINE_ALPHA, + JoglTextureUtil.getGLCombineFuncAlpha(alphaCombineFunc)); + } unitRecord.alphaCombineFunc = alphaCombineFunc; } @@ -1048,8 +1084,10 @@ public class JoglTextureStateUtil { checkAndSetUnit(unit, record, caps); checked = true; } - gl.getGL2ES1().glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2.GL_SOURCE0_ALPHA, - JoglTextureUtil.getGLCombineSrc(combSrcAlpha)); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2.GL_SOURCE0_ALPHA, + JoglTextureUtil.getGLCombineSrc(combSrcAlpha)); + } unitRecord.combSrcAlpha0 = combSrcAlpha; } @@ -1059,8 +1097,10 @@ public class JoglTextureStateUtil { checkAndSetUnit(unit, record, caps); checked = true; } - gl.getGL2ES1().glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2ES1.GL_OPERAND0_ALPHA, - JoglTextureUtil.getGLCombineOpAlpha(combOpAlpha)); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2ES1.GL_OPERAND0_ALPHA, + JoglTextureUtil.getGLCombineOpAlpha(combOpAlpha)); + } unitRecord.combOpAlpha0 = combOpAlpha; } @@ -1073,8 +1113,10 @@ public class JoglTextureStateUtil { checkAndSetUnit(unit, record, caps); checked = true; } - gl.getGL2ES1().glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2.GL_SOURCE1_ALPHA, - JoglTextureUtil.getGLCombineSrc(combSrcAlpha)); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2.GL_SOURCE1_ALPHA, + JoglTextureUtil.getGLCombineSrc(combSrcAlpha)); + } unitRecord.combSrcAlpha1 = combSrcAlpha; } @@ -1084,8 +1126,10 @@ public class JoglTextureStateUtil { checkAndSetUnit(unit, record, caps); checked = true; } - gl.getGL2ES1().glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2ES1.GL_OPERAND1_ALPHA, - JoglTextureUtil.getGLCombineOpAlpha(combOpAlpha)); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2ES1.GL_OPERAND1_ALPHA, + JoglTextureUtil.getGLCombineOpAlpha(combOpAlpha)); + } unitRecord.combOpAlpha1 = combOpAlpha; } @@ -1098,8 +1142,10 @@ public class JoglTextureStateUtil { checkAndSetUnit(unit, record, caps); checked = true; } - gl.getGL2ES1().glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2.GL_SOURCE2_ALPHA, - JoglTextureUtil.getGLCombineSrc(combSrcAlpha)); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2.GL_SOURCE2_ALPHA, + JoglTextureUtil.getGLCombineSrc(combSrcAlpha)); + } unitRecord.combSrcAlpha2 = combSrcAlpha; } @@ -1109,8 +1155,10 @@ public class JoglTextureStateUtil { checkAndSetUnit(unit, record, caps); checked = true; } - gl.getGL2ES1().glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2ES1.GL_OPERAND2_ALPHA, - JoglTextureUtil.getGLCombineOpAlpha(combOpAlpha)); + if (gl.isGL2ES1()) { + gl.getGL2ES1().glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2ES1.GL_OPERAND2_ALPHA, + JoglTextureUtil.getGLCombineOpAlpha(combOpAlpha)); + } unitRecord.combOpAlpha2 = combOpAlpha; } } @@ -1177,7 +1225,12 @@ public class JoglTextureStateUtil { TextureRecord.colorBuffer.put(texBorder.getRed()).put(texBorder.getGreen()).put(texBorder.getBlue()) .put(texBorder.getAlpha()); TextureRecord.colorBuffer.rewind(); - gl.glTexParameterfv(getGLType(texture.getType()), GL2GL3.GL_TEXTURE_BORDER_COLOR, TextureRecord.colorBuffer); + if (gl.isGL2GL3()) { + final int glType = getGLType(texture.getType()); + if (glType != GL.GL_INVALID_ENUM) { + gl.glTexParameterfv(glType, GL2GL3.GL_TEXTURE_BORDER_COLOR, TextureRecord.colorBuffer); + } + } texRecord.borderColor.set(texBorder); } } @@ -1392,58 +1445,89 @@ public class JoglTextureStateUtil { if (!unitRecord.isValid()) { checkAndSetUnit(unit, record, caps); - if (genS) { - gl.glEnable(GL2.GL_TEXTURE_GEN_S); + if (gl.isGL2()) { + gl.glEnable(GL2.GL_TEXTURE_GEN_S); + } } else { - gl.glDisable(GL2.GL_TEXTURE_GEN_S); + if (gl.isGL2()) { + gl.glDisable(GL2.GL_TEXTURE_GEN_S); + } } if (genT) { - gl.glEnable(GL2.GL_TEXTURE_GEN_T); + if (gl.isGL2()) { + gl.glEnable(GL2.GL_TEXTURE_GEN_T); + } } else { - gl.glDisable(GL2.GL_TEXTURE_GEN_T); + if (gl.isGL2()) { + gl.glDisable(GL2.GL_TEXTURE_GEN_T); + } } if (genR) { - gl.glEnable(GL2.GL_TEXTURE_GEN_R); + if (gl.isGL2()) { + gl.glEnable(GL2.GL_TEXTURE_GEN_R); + } } else { - gl.glDisable(GL2.GL_TEXTURE_GEN_R); + if (gl.isGL2()) { + gl.glDisable(GL2.GL_TEXTURE_GEN_R); + } } if (genQ) { - gl.glEnable(GL2.GL_TEXTURE_GEN_Q); + if (gl.isGL2()) { + gl.glEnable(GL2.GL_TEXTURE_GEN_Q); + } } else { - gl.glDisable(GL2.GL_TEXTURE_GEN_Q); + if (gl.isGL2()) { + gl.glDisable(GL2.GL_TEXTURE_GEN_Q); + } } } else { if (genS != unitRecord.textureGenS) { checkAndSetUnit(unit, record, caps); if (genS) { - gl.glEnable(GL2.GL_TEXTURE_GEN_S); + if (gl.isGL2()) { + gl.glEnable(GL2.GL_TEXTURE_GEN_S); + } } else { - gl.glDisable(GL2.GL_TEXTURE_GEN_S); + if (gl.isGL2()) { + gl.glDisable(GL2.GL_TEXTURE_GEN_S); + } } } if (genT != unitRecord.textureGenT) { checkAndSetUnit(unit, record, caps); if (genT) { - gl.glEnable(GL2.GL_TEXTURE_GEN_T); + if (gl.isGL2()) { + gl.glEnable(GL2.GL_TEXTURE_GEN_T); + } } else { - gl.glDisable(GL2.GL_TEXTURE_GEN_T); + if (gl.isGL2()) { + gl.glDisable(GL2.GL_TEXTURE_GEN_T); + } } } if (genR != unitRecord.textureGenR) { checkAndSetUnit(unit, record, caps); if (genR) { - gl.glEnable(GL2.GL_TEXTURE_GEN_R); + if (gl.isGL2()) { + gl.glEnable(GL2.GL_TEXTURE_GEN_R); + } } else { - gl.glDisable(GL2.GL_TEXTURE_GEN_R); + if (gl.isGL2()) { + gl.glDisable(GL2.GL_TEXTURE_GEN_R); + } } } if (genQ != unitRecord.textureGenQ) { checkAndSetUnit(unit, record, caps); if (genQ) { - gl.glEnable(GL2.GL_TEXTURE_GEN_Q); + if (gl.isGL2()) { + gl.glEnable(GL2.GL_TEXTURE_GEN_Q); + } } else { - gl.glDisable(GL2.GL_TEXTURE_GEN_Q); + if (gl.isGL2()) { + gl.glDisable(GL2.GL_TEXTURE_GEN_Q); + } } } } @@ -1490,7 +1574,12 @@ public class JoglTextureStateUtil { // set up magnification filter if (!texRecord.isValid() || texRecord.depthTextureMode != depthMode) { checkAndSetUnit(unit, record, caps); - gl.glTexParameteri(getGLType(type), GL2.GL_DEPTH_TEXTURE_MODE, depthMode); + if (gl.isGL2()) { + final int glType = getGLType(texture.getType()); + if (glType != GL.GL_INVALID_ENUM) { + gl.glTexParameteri(glType, GL2.GL_DEPTH_TEXTURE_MODE, depthMode); + } + } texRecord.depthTextureMode = depthMode; } } @@ -1533,7 +1622,10 @@ public class JoglTextureStateUtil { // set up magnification filter if (!texRecord.isValid() || texRecord.magFilter != magFilter) { checkAndSetUnit(unit, record, caps); - gl.glTexParameteri(getGLType(type), GL.GL_TEXTURE_MAG_FILTER, magFilter); + final int glType = getGLType(texture.getType()); + if (glType != GL.GL_INVALID_ENUM) { + gl.glTexParameteri(glType, GL.GL_TEXTURE_MAG_FILTER, magFilter); + } texRecord.magFilter = magFilter; } @@ -1580,17 +1672,23 @@ public class JoglTextureStateUtil { if (!texRecord.isValid() || texRecord.wrapS != wrapS) { checkAndSetUnit(unit, record, caps); - gl.glTexParameteri(GL2ES2.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_S, wrapS); + if (gl.isGL2ES2()) { + gl.glTexParameteri(GL2ES2.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_S, wrapS); + } texRecord.wrapS = wrapS; } if (!texRecord.isValid() || texRecord.wrapT != wrapT) { checkAndSetUnit(unit, record, caps); - gl.glTexParameteri(GL2ES2.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_T, wrapT); + if (gl.isGL2ES2()) { + gl.glTexParameteri(GL2ES2.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_T, wrapT); + } texRecord.wrapT = wrapT; } if (!texRecord.isValid() || texRecord.wrapR != wrapR) { checkAndSetUnit(unit, record, caps); - gl.glTexParameteri(GL2ES2.GL_TEXTURE_3D, GL2ES2.GL_TEXTURE_WRAP_R, wrapR); + if (gl.isGL2ES2()) { + gl.glTexParameteri(GL2ES2.GL_TEXTURE_3D, GL2ES2.GL_TEXTURE_WRAP_R, wrapR); + } texRecord.wrapR = wrapR; } @@ -1613,7 +1711,9 @@ public class JoglTextureStateUtil { if (!texRecord.isValid() || texRecord.wrapS != wrapS) { checkAndSetUnit(unit, record, caps); - gl.glTexParameteri(GL2GL3.GL_TEXTURE_1D, GL.GL_TEXTURE_WRAP_S, wrapS); + if (gl.isGL2GL3()) { + gl.glTexParameteri(GL2GL3.GL_TEXTURE_1D, GL.GL_TEXTURE_WRAP_S, wrapS); + } texRecord.wrapS = wrapS; } } @@ -1775,7 +1875,10 @@ public class JoglTextureStateUtil { checkAndSetUnit(unit, record, caps); final int id = texture.getTextureIdForContext(context.getGlContextRep()); - gl.glBindTexture(getGLType(texture.getType()), id); + final int glType = getGLType(texture.getType()); + if (glType != GL.GL_INVALID_ENUM) { + gl.glBindTexture(glType, id); + } if (Constants.stats) { StatCollector.addStat(StatType.STAT_TEXTURE_BINDS, 1); } @@ -1785,13 +1888,22 @@ public class JoglTextureStateUtil { } public static int getGLType(final Type type) { + final GL gl = GLContext.getCurrentGL(); switch (type) { case TwoDimensional: return GL.GL_TEXTURE_2D; case OneDimensional: - return GL2GL3.GL_TEXTURE_1D; + if (gl.isGL2GL3()) { + return GL2GL3.GL_TEXTURE_1D; + } else { + return GL.GL_INVALID_ENUM; + } case ThreeDimensional: - return GL2ES2.GL_TEXTURE_3D; + if (gl.isGL2ES2()) { + return GL2ES2.GL_TEXTURE_3D; + } else { + return GL.GL_INVALID_ENUM; + } case CubeMap: return GL.GL_TEXTURE_CUBE_MAP; case Rectangle: diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglWireframeStateUtil.java b/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglWireframeStateUtil.java index 7172fc0..fc8c312 100644 --- a/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglWireframeStateUtil.java +++ b/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglWireframeStateUtil.java @@ -58,26 +58,36 @@ public abstract class JoglWireframeStateUtil { if (record.isValid()) { if (frontMode == backMode && (record.frontMode != frontMode || record.backMode != backMode)) { - gl.getGL2GL3().glPolygonMode(GL.GL_FRONT_AND_BACK, frontMode); + if (gl.isGL2GL3()) { + gl.getGL2GL3().glPolygonMode(GL.GL_FRONT_AND_BACK, frontMode); + } record.frontMode = frontMode; record.backMode = backMode; } else if (frontMode != backMode) { if (record.frontMode != frontMode) { - gl.getGL2GL3().glPolygonMode(GL.GL_FRONT, frontMode); + if (gl.isGL2GL3()) { + gl.getGL2GL3().glPolygonMode(GL.GL_FRONT, frontMode); + } record.frontMode = frontMode; } if (record.backMode != backMode) { - gl.getGL2GL3().glPolygonMode(GL.GL_BACK, backMode); + if (gl.isGL2GL3()) { + gl.getGL2GL3().glPolygonMode(GL.GL_BACK, backMode); + } record.backMode = backMode; } } } else { if (frontMode == backMode) { - gl.getGL2GL3().glPolygonMode(GL.GL_FRONT_AND_BACK, frontMode); + if (gl.isGL2GL3()) { + gl.getGL2GL3().glPolygonMode(GL.GL_FRONT_AND_BACK, frontMode); + } } else if (frontMode != backMode) { - gl.getGL2GL3().glPolygonMode(GL.GL_FRONT, frontMode); - gl.getGL2GL3().glPolygonMode(GL.GL_BACK, backMode); + if (gl.isGL2GL3()) { + gl.getGL2GL3().glPolygonMode(GL.GL_FRONT, frontMode); + gl.getGL2GL3().glPolygonMode(GL.GL_BACK, backMode); + } } record.frontMode = frontMode; record.backMode = backMode; 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 3931796..de3f37c 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,8 +106,10 @@ public abstract class JoglShaderUtil { final GL gl = GLContext.getCurrentGL(); if (variable.variableID == -1) { - variable.variableID = gl.getGL2ES2().glGetUniformLocation(programID, variable.name); // TODO Check - // variable.name + if (gl.isGL2ES2()) { + variable.variableID = gl.getGL2ES2().glGetUniformLocation(programID, variable.name); // TODO Check + // variable.name + } if (variable.variableID == -1 && !variable.errorLogged) { logger.severe("Shader uniform [" + variable.name + "] could not be located in shader"); @@ -119,27 +121,35 @@ public abstract class JoglShaderUtil { private static void updateShaderUniform(final ShaderVariableInt shaderUniform) { final GL gl = GLContext.getCurrentGL(); - gl.getGL2ES2().glUniform1i(shaderUniform.variableID, shaderUniform.value1); + if (gl.isGL2ES2()) { + gl.getGL2ES2().glUniform1i(shaderUniform.variableID, shaderUniform.value1); + } } private static void updateShaderUniform(final ShaderVariableInt2 shaderUniform) { final GL gl = GLContext.getCurrentGL(); - gl.getGL2ES2().glUniform2i(shaderUniform.variableID, shaderUniform.value1, shaderUniform.value2); + if (gl.isGL2ES2()) { + gl.getGL2ES2().glUniform2i(shaderUniform.variableID, shaderUniform.value1, shaderUniform.value2); + } } private static void updateShaderUniform(final ShaderVariableInt3 shaderUniform) { final GL gl = GLContext.getCurrentGL(); - gl.getGL2ES2().glUniform3i(shaderUniform.variableID, shaderUniform.value1, shaderUniform.value2, - shaderUniform.value3); + if (gl.isGL2ES2()) { + gl.getGL2ES2().glUniform3i(shaderUniform.variableID, shaderUniform.value1, shaderUniform.value2, + shaderUniform.value3); + } } private static void updateShaderUniform(final ShaderVariableInt4 shaderUniform) { final GL gl = GLContext.getCurrentGL(); - gl.getGL2ES2().glUniform4i(shaderUniform.variableID, shaderUniform.value1, shaderUniform.value2, - shaderUniform.value3, shaderUniform.value4); + if (gl.isGL2ES2()) { + gl.getGL2ES2().glUniform4i(shaderUniform.variableID, shaderUniform.value1, shaderUniform.value2, + shaderUniform.value3, shaderUniform.value4); + } } private static void updateShaderUniform(final ShaderVariableIntArray shaderUniform) { @@ -147,20 +157,28 @@ public abstract class JoglShaderUtil { switch (shaderUniform.size) { case 1: - gl.getGL2ES2().glUniform1iv(shaderUniform.variableID, shaderUniform.value.remaining(), - shaderUniform.value); + if (gl.isGL2ES2()) { + gl.getGL2ES2().glUniform1iv(shaderUniform.variableID, shaderUniform.value.remaining(), + shaderUniform.value); + } break; case 2: - gl.getGL2ES2().glUniform2iv(shaderUniform.variableID, shaderUniform.value.remaining(), - shaderUniform.value); + if (gl.isGL2ES2()) { + gl.getGL2ES2().glUniform2iv(shaderUniform.variableID, shaderUniform.value.remaining(), + shaderUniform.value); + } break; case 3: - gl.getGL2ES2().glUniform3iv(shaderUniform.variableID, shaderUniform.value.remaining(), - shaderUniform.value); + if (gl.isGL2ES2()) { + gl.getGL2ES2().glUniform3iv(shaderUniform.variableID, shaderUniform.value.remaining(), + shaderUniform.value); + } break; case 4: - gl.getGL2ES2().glUniform4iv(shaderUniform.variableID, shaderUniform.value.remaining(), - shaderUniform.value); + if (gl.isGL2ES2()) { + gl.getGL2ES2().glUniform4iv(shaderUniform.variableID, shaderUniform.value.remaining(), + shaderUniform.value); + } break; default: throw new IllegalArgumentException("Wrong size: " + shaderUniform.size); @@ -170,27 +188,35 @@ public abstract class JoglShaderUtil { private static void updateShaderUniform(final ShaderVariableFloat shaderUniform) { final GL gl = GLContext.getCurrentGL(); - gl.getGL2ES2().glUniform1f(shaderUniform.variableID, shaderUniform.value1); + if (gl.isGL2ES2()) { + gl.getGL2ES2().glUniform1f(shaderUniform.variableID, shaderUniform.value1); + } } private static void updateShaderUniform(final ShaderVariableFloat2 shaderUniform) { final GL gl = GLContext.getCurrentGL(); - gl.getGL2ES2().glUniform2f(shaderUniform.variableID, shaderUniform.value1, shaderUniform.value2); + if (gl.isGL2ES2()) { + gl.getGL2ES2().glUniform2f(shaderUniform.variableID, shaderUniform.value1, shaderUniform.value2); + } } private static void updateShaderUniform(final ShaderVariableFloat3 shaderUniform) { final GL gl = GLContext.getCurrentGL(); - gl.getGL2ES2().glUniform3f(shaderUniform.variableID, shaderUniform.value1, shaderUniform.value2, - shaderUniform.value3); + if (gl.isGL2ES2()) { + gl.getGL2ES2().glUniform3f(shaderUniform.variableID, shaderUniform.value1, shaderUniform.value2, + shaderUniform.value3); + } } private static void updateShaderUniform(final ShaderVariableFloat4 shaderUniform) { final GL gl = GLContext.getCurrentGL(); - gl.getGL2ES2().glUniform4f(shaderUniform.variableID, shaderUniform.value1, shaderUniform.value2, - shaderUniform.value3, shaderUniform.value4); + if (gl.isGL2ES2()) { + gl.getGL2ES2().glUniform4f(shaderUniform.variableID, shaderUniform.value1, shaderUniform.value2, + shaderUniform.value3, shaderUniform.value4); + } } private static void updateShaderUniform(final ShaderVariableFloatArray shaderUniform) { @@ -198,20 +224,28 @@ public abstract class JoglShaderUtil { switch (shaderUniform.size) { case 1: - gl.getGL2ES2().glUniform1fv(shaderUniform.variableID, shaderUniform.value.remaining(), - shaderUniform.value); + if (gl.isGL2ES2()) { + gl.getGL2ES2().glUniform1fv(shaderUniform.variableID, shaderUniform.value.remaining(), + shaderUniform.value); + } break; case 2: - gl.getGL2ES2().glUniform2fv(shaderUniform.variableID, shaderUniform.value.remaining(), - shaderUniform.value); + if (gl.isGL2ES2()) { + gl.getGL2ES2().glUniform2fv(shaderUniform.variableID, shaderUniform.value.remaining(), + shaderUniform.value); + } break; case 3: - gl.getGL2ES2().glUniform3fv(shaderUniform.variableID, shaderUniform.value.remaining(), - shaderUniform.value); + if (gl.isGL2ES2()) { + gl.getGL2ES2().glUniform3fv(shaderUniform.variableID, shaderUniform.value.remaining(), + shaderUniform.value); + } break; case 4: - gl.getGL2ES2().glUniform4fv(shaderUniform.variableID, shaderUniform.value.remaining(), - shaderUniform.value); + if (gl.isGL2ES2()) { + gl.getGL2ES2().glUniform4fv(shaderUniform.variableID, shaderUniform.value.remaining(), + shaderUniform.value); + } break; default: throw new IllegalArgumentException("Wrong size: " + shaderUniform.size); @@ -222,24 +256,30 @@ public abstract class JoglShaderUtil { final GL gl = GLContext.getCurrentGL(); shaderUniform.matrixBuffer.rewind(); - gl.getGL2ES2().glUniformMatrix2fv(shaderUniform.variableID, 1, shaderUniform.rowMajor, - shaderUniform.matrixBuffer); + if (gl.isGL2ES2()) { + gl.getGL2ES2().glUniformMatrix2fv(shaderUniform.variableID, 1, shaderUniform.rowMajor, + shaderUniform.matrixBuffer); + } } private static void updateShaderUniform(final ShaderVariableMatrix3 shaderUniform) { final GL gl = GLContext.getCurrentGL(); shaderUniform.matrixBuffer.rewind(); - gl.getGL2ES2().glUniformMatrix3fv(shaderUniform.variableID, 1, shaderUniform.rowMajor, - shaderUniform.matrixBuffer); + if (gl.isGL2ES2()) { + gl.getGL2ES2().glUniformMatrix3fv(shaderUniform.variableID, 1, shaderUniform.rowMajor, + shaderUniform.matrixBuffer); + } } private static void updateShaderUniform(final ShaderVariableMatrix4 shaderUniform) { final GL gl = GLContext.getCurrentGL(); shaderUniform.matrixBuffer.rewind(); - gl.getGL2ES2().glUniformMatrix4fv(shaderUniform.variableID, 1, shaderUniform.rowMajor, - shaderUniform.matrixBuffer); + if (gl.isGL2ES2()) { + gl.getGL2ES2().glUniformMatrix4fv(shaderUniform.variableID, 1, shaderUniform.rowMajor, + shaderUniform.matrixBuffer); + } } private static void updateShaderUniform(final ShaderVariableMatrix4Array shaderUniform) { @@ -247,8 +287,10 @@ public abstract class JoglShaderUtil { shaderUniform.matrixBuffer.rewind(); // count == number of matrices we are sending, or iotw, limit / 16 - gl.getGL2ES2().glUniformMatrix4fv(shaderUniform.variableID, shaderUniform.matrixBuffer.limit() >> 4, - shaderUniform.rowMajor, shaderUniform.matrixBuffer); + if (gl.isGL2ES2()) { + gl.getGL2ES2().glUniformMatrix4fv(shaderUniform.variableID, shaderUniform.matrixBuffer.limit() >> 4, + shaderUniform.rowMajor, shaderUniform.matrixBuffer); + } } /** @@ -263,8 +305,10 @@ public abstract class JoglShaderUtil { final GL gl = GLContext.getCurrentGL(); if (variable.variableID == -1) { - variable.variableID = gl.getGL2ES2().glGetAttribLocation(programID, variable.name); // TODO Check - // variable.name + if (gl.isGL2ES2()) { + variable.variableID = gl.getGL2ES2().glGetAttribLocation(programID, variable.name); // TODO Check + // variable.name + } if (variable.variableID == -1 && !variable.errorLogged) { logger.severe("Shader attribute [" + variable.name + "] could not be located in shader"); @@ -335,12 +379,16 @@ public abstract class JoglShaderUtil { private static void enableVertexAttribute(final ShaderVariable var, final ShaderObjectsStateRecord record) { if (!record.enabledAttributes.contains(var)) { + final GL gl = GLContext.getCurrentGL(); if (var.getSize() == 1) { - GLContext.getCurrentGL().getGL2ES2().glEnableVertexAttribArray(var.variableID); + if (gl.isGL2ES2()) { + gl.getGL2ES2().glEnableVertexAttribArray(var.variableID); + } } else { - final GL gl = GLContext.getCurrentGL(); - for (int i = 0, max = var.getSize(); i < max; i++) { - gl.getGL2ES2().glEnableVertexAttribArray(var.variableID + i); + if (gl.isGL2ES2()) { + for (int i = 0, max = var.getSize(); i < max; i++) { + gl.getGL2ES2().glEnableVertexAttribArray(var.variableID + i); + } } } record.enabledAttributes.add(var); @@ -350,22 +398,21 @@ public abstract class JoglShaderUtil { private static void updateShaderAttribute(final ShaderVariablePointerFloat variable, final ShaderObjectsStateRecord record, final boolean useVBO) { enableVertexAttribute(variable, record); + final GL gl = GLContext.getCurrentGL(); if (useVBO) { final RenderContext context = ContextManager.getCurrentContext(); final int vboId = JoglRenderer.setupVBO(variable.data, context); JoglRendererUtil.setBoundVBO(context.getRendererRecord(), vboId); - GLContext - .getCurrentGL() - .getGL2ES2() - .glVertexAttribPointer(variable.variableID, variable.size, GL.GL_FLOAT, variable.normalized, - variable.stride, 0); + if (gl.isGL2ES2()) { + gl.getGL2ES2().glVertexAttribPointer(variable.variableID, variable.size, GL.GL_FLOAT, + variable.normalized, variable.stride, 0); + } } else { variable.data.getBuffer().rewind(); - GLContext - .getCurrentGL() - .getGL2() - .glVertexAttribPointer(variable.variableID, variable.size, GL.GL_FLOAT, variable.normalized, - variable.stride, variable.data.getBuffer()); + if (gl.isGL2()) { + gl.getGL2().glVertexAttribPointer(variable.variableID, variable.size, GL.GL_FLOAT, variable.normalized, + variable.stride, variable.data.getBuffer()); + } } } @@ -382,13 +429,17 @@ public abstract class JoglShaderUtil { if (useVBO) { final int vboId = JoglRenderer.setupVBO(variable.data, context); JoglRendererUtil.setBoundVBO(context.getRendererRecord(), vboId); - gl.getGL2ES2().glVertexAttribPointer(variable.variableID + i, size, GL.GL_FLOAT, variable.normalized, - 0, pos); + if (gl.isGL2ES2()) { + 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.getGL2().glVertexAttribPointer(variable.variableID + i, size, GL.GL_FLOAT, variable.normalized, 0, - variable.data.getBuffer()); + if (gl.isGL2()) { + gl.getGL2().glVertexAttribPointer(variable.variableID + i, size, GL.GL_FLOAT, variable.normalized, + 0, variable.data.getBuffer()); + } } } } @@ -396,72 +447,70 @@ public abstract class JoglShaderUtil { private static void updateShaderAttribute(final ShaderVariablePointerByte variable, final ShaderObjectsStateRecord record, final boolean useVBO) { enableVertexAttribute(variable, record); + final GL gl = GLContext.getCurrentGL(); if (useVBO) { final RenderContext context = ContextManager.getCurrentContext(); final int vboId = JoglRenderer.setupVBO(variable.data, context); JoglRendererUtil.setBoundVBO(context.getRendererRecord(), vboId); - GLContext - .getCurrentGL() - .getGL2ES2() - .glVertexAttribPointer(variable.variableID, variable.size, - variable.unsigned ? GL.GL_UNSIGNED_BYTE : GL.GL_BYTE, variable.normalized, variable.stride, - 0); + if (gl.isGL2ES2()) { + gl.getGL2ES2().glVertexAttribPointer(variable.variableID, variable.size, + variable.unsigned ? GL.GL_UNSIGNED_BYTE : GL.GL_BYTE, variable.normalized, variable.stride, 0); + } } else { variable.data.getBuffer().rewind(); - GLContext - .getCurrentGL() - .getGL2() - .glVertexAttribPointer(variable.variableID, variable.size, - variable.unsigned ? GL.GL_UNSIGNED_BYTE : GL.GL_BYTE, variable.normalized, variable.stride, - variable.data.getBuffer()); + if (gl.isGL2()) { + gl.getGL2().glVertexAttribPointer(variable.variableID, variable.size, + variable.unsigned ? GL.GL_UNSIGNED_BYTE : GL.GL_BYTE, variable.normalized, variable.stride, + variable.data.getBuffer()); + } } } private static void updateShaderAttribute(final ShaderVariablePointerInt variable, final ShaderObjectsStateRecord record, final boolean useVBO) { enableVertexAttribute(variable, record); + final GL gl = GLContext.getCurrentGL(); if (useVBO) { final RenderContext context = ContextManager.getCurrentContext(); final int vboId = JoglRenderer.setupVBO(variable.data, context); JoglRendererUtil.setBoundVBO(context.getRendererRecord(), vboId); - GLContext - .getCurrentGL() - .getGL2ES2() - .glVertexAttribPointer(variable.variableID, variable.size, - variable.unsigned ? GL.GL_UNSIGNED_INT : GL2ES2.GL_INT, variable.normalized, - variable.stride, 0); + if (gl.isGL2ES2()) { + gl.getGL2ES2() + .glVertexAttribPointer(variable.variableID, variable.size, + variable.unsigned ? GL.GL_UNSIGNED_INT : GL2ES2.GL_INT, variable.normalized, + variable.stride, 0); + } } else { variable.data.getBuffer().rewind(); - GLContext - .getCurrentGL() - .getGL2() - .glVertexAttribPointer(variable.variableID, variable.size, - variable.unsigned ? GL.GL_UNSIGNED_INT : GL2ES2.GL_INT, variable.normalized, - variable.stride, variable.data.getBuffer()); + if (gl.isGL2()) { + gl.getGL2().glVertexAttribPointer(variable.variableID, variable.size, + variable.unsigned ? GL.GL_UNSIGNED_INT : GL2ES2.GL_INT, variable.normalized, variable.stride, + variable.data.getBuffer()); + } } } private static void updateShaderAttribute(final ShaderVariablePointerShort variable, final ShaderObjectsStateRecord record, final boolean useVBO) { enableVertexAttribute(variable, record); + final GL gl = GLContext.getCurrentGL(); if (useVBO) { final RenderContext context = ContextManager.getCurrentContext(); final int vboId = JoglRenderer.setupVBO(variable.data, context); JoglRendererUtil.setBoundVBO(context.getRendererRecord(), vboId); - GLContext - .getCurrentGL() - .getGL2ES2() - .glVertexAttribPointer(variable.variableID, variable.size, - variable.unsigned ? GL.GL_UNSIGNED_SHORT : GL.GL_SHORT, variable.normalized, - variable.stride, 0); + if (gl.isGL2ES2()) { + gl.getGL2ES2() + .glVertexAttribPointer(variable.variableID, variable.size, + variable.unsigned ? GL.GL_UNSIGNED_SHORT : GL.GL_SHORT, variable.normalized, + variable.stride, 0); + } } else { variable.data.getBuffer().rewind(); - GLContext - .getCurrentGL() - .getGL2() - .glVertexAttribPointer(variable.variableID, variable.size, - variable.unsigned ? GL.GL_UNSIGNED_SHORT : GL.GL_SHORT, variable.normalized, - variable.stride, variable.data.getBuffer()); + if (gl.isGL2()) { + gl.getGL2().glVertexAttribPointer(variable.variableID, variable.size, + variable.unsigned ? GL.GL_UNSIGNED_SHORT : GL.GL_SHORT, variable.normalized, variable.stride, + variable.data.getBuffer()); + } } } } |