diff options
6 files changed, 51 insertions, 11 deletions
diff --git a/ardor3d-core/src/main/java/com/ardor3d/renderer/ContextCapabilities.java b/ardor3d-core/src/main/java/com/ardor3d/renderer/ContextCapabilities.java index 3e8d55c..9599e0e 100644 --- a/ardor3d-core/src/main/java/com/ardor3d/renderer/ContextCapabilities.java +++ b/ardor3d-core/src/main/java/com/ardor3d/renderer/ContextCapabilities.java @@ -16,6 +16,8 @@ public class ContextCapabilities { protected boolean _supportsGL1_2 = false; protected boolean _supportsMultisample = false; + protected boolean _supportsDoubleCoefficientsInClipPlaneEquation = false; + protected boolean _supportsConstantColor = false; protected boolean _supportsEq = false; protected boolean _supportsSeparateEq = false; @@ -186,6 +188,7 @@ public class ContextCapabilities { _supportsMirrorEdgeClamp = source._supportsMirrorEdgeClamp; _supportsMirroredRepeat = source._supportsMirroredRepeat; _supportsMultisample = source._supportsMultisample; + _supportsDoubleCoefficientsInClipPlaneEquation = source._supportsDoubleCoefficientsInClipPlaneEquation; _supportsMultiTexture = source._supportsMultiTexture; _supportsNonPowerTwo = source._supportsNonPowerTwo; _supportsPointParameters = source._supportsPointParameters; @@ -229,6 +232,13 @@ public class ContextCapabilities { } /** + * @return true if double coefficients are supported in clip plane equation + */ + public boolean areDoubleCoefficientsInClipPlaneEquationSupported() { + return _supportsDoubleCoefficientsInClipPlaneEquation; + } + + /** * @return true if we support fbo multisampling (antialiasing) */ public boolean isFBOMultisampleSupported() { diff --git a/ardor3d-core/src/main/java/com/ardor3d/renderer/state/record/ClipStateRecord.java b/ardor3d-core/src/main/java/com/ardor3d/renderer/state/record/ClipStateRecord.java index 7dba025..eeedf23 100644 --- a/ardor3d-core/src/main/java/com/ardor3d/renderer/state/record/ClipStateRecord.java +++ b/ardor3d-core/src/main/java/com/ardor3d/renderer/state/record/ClipStateRecord.java @@ -10,16 +10,31 @@ package com.ardor3d.renderer.state.record; -import java.nio.DoubleBuffer; +import java.nio.Buffer; import java.util.Arrays; +import com.ardor3d.renderer.ContextCapabilities; +import com.ardor3d.renderer.ContextManager; +import com.ardor3d.renderer.RenderContext; import com.ardor3d.renderer.state.ClipState; import com.ardor3d.util.geom.BufferUtils; public class ClipStateRecord extends StateRecord { - public final boolean[] planeEnabled = new boolean[ClipState.MAX_CLIP_PLANES]; - public final DoubleBuffer buf = BufferUtils.createDoubleBuffer(4); + public final boolean[] planeEnabled; + public final Buffer buf; + + public ClipStateRecord() { + planeEnabled = new boolean[ClipState.MAX_CLIP_PLANES]; + final RenderContext context = ContextManager.getCurrentContext(); + final ContextCapabilities caps = context.getCapabilities(); + if (caps.areDoubleCoefficientsInClipPlaneEquationSupported()) { + buf = BufferUtils.createDoubleBuffer(4); + } else { + buf = BufferUtils.createFloatBuffer(4); + } + + } @Override public void invalidate() { 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 bfb39bd..036f9d3 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 @@ -43,6 +43,7 @@ public class JoglContextCapabilities extends ContextCapabilities { _supportsVBO = gl.isExtensionAvailable("GL_ARB_vertex_buffer_object"); _supportsGL1_2 = gl.isExtensionAvailable("GL_VERSION_1_2"); _supportsMultisample = gl.isExtensionAvailable("GL_ARB_multisample"); + _supportsDoubleCoefficientsInClipPlaneEquation = !gl.isGLES1(); _supportsConstantColor = _supportsEq = gl.isExtensionAvailable("GL_ARB_imaging"); _supportsSeparateFunc = gl.isExtensionAvailable("GL_EXT_blend_func_separate"); 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 8dfc993..33795a6 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 @@ -10,6 +10,9 @@ package com.ardor3d.scene.state.jogl; +import java.nio.DoubleBuffer; +import java.nio.FloatBuffer; + import javax.media.opengl.GL; import javax.media.opengl.GL2ES1; import javax.media.opengl.GLContext; @@ -59,13 +62,21 @@ public abstract class JoglClipStateUtil { } record.planeEnabled[planeIndex] = true; } - - record.buf.rewind(); - record.buf.put(state.getPlaneEquations(planeIndex)); - record.buf.flip(); if (gl.isGL2ES1()) { - // TODO Shouldn't glClipPlane be in GL2ES1? - gl.getGL2().glClipPlane(GL2ES1.GL_CLIP_PLANE0 + planeIndex, record.buf); + record.buf.rewind(); + if (gl.isGLES1()) { + for (final double planeEqCoeff : state.getPlaneEquations(planeIndex)) { + ((FloatBuffer) record.buf).put((float) planeEqCoeff); + } + gl.getGLES1().glClipPlanef(GL2ES1.GL_CLIP_PLANE0 + planeIndex, (FloatBuffer) record.buf); + } else { + ((DoubleBuffer) record.buf).put(state.getPlaneEquations(planeIndex)); + gl.getGL2().glClipPlane(GL2ES1.GL_CLIP_PLANE0 + planeIndex, (DoubleBuffer) record.buf); + } + record.buf.flip(); + } else { + // TODO use this suggestion but take into account the good reference frame: + // http://stackoverflow.com/a/13705204 } } else { diff --git a/ardor3d-lwjgl/src/main/java/com/ardor3d/renderer/lwjgl/LwjglContextCapabilities.java b/ardor3d-lwjgl/src/main/java/com/ardor3d/renderer/lwjgl/LwjglContextCapabilities.java index 20e2be3..9855987 100644 --- a/ardor3d-lwjgl/src/main/java/com/ardor3d/renderer/lwjgl/LwjglContextCapabilities.java +++ b/ardor3d-lwjgl/src/main/java/com/ardor3d/renderer/lwjgl/LwjglContextCapabilities.java @@ -38,6 +38,7 @@ public class LwjglContextCapabilities extends ContextCapabilities { _supportsVBO = caps.GL_ARB_vertex_buffer_object; _supportsGL1_2 = caps.OpenGL12; _supportsMultisample = caps.GL_ARB_multisample; + _supportsDoubleCoefficientsInClipPlaneEquation = true; _supportsConstantColor = _supportsEq = caps.GL_ARB_imaging; _supportsSeparateFunc = caps.GL_EXT_blend_func_separate; diff --git a/ardor3d-lwjgl/src/main/java/com/ardor3d/scene/state/lwjgl/LwjglClipStateUtil.java b/ardor3d-lwjgl/src/main/java/com/ardor3d/scene/state/lwjgl/LwjglClipStateUtil.java index d3ee2a0..581cbb5 100644 --- a/ardor3d-lwjgl/src/main/java/com/ardor3d/scene/state/lwjgl/LwjglClipStateUtil.java +++ b/ardor3d-lwjgl/src/main/java/com/ardor3d/scene/state/lwjgl/LwjglClipStateUtil.java @@ -10,6 +10,8 @@ package com.ardor3d.scene.state.lwjgl; +import java.nio.DoubleBuffer; + import org.lwjgl.opengl.GL11; import com.ardor3d.renderer.ContextCapabilities; @@ -54,9 +56,9 @@ public abstract class LwjglClipStateUtil { } record.buf.rewind(); - record.buf.put(state.getPlaneEquations(planeIndex)); + ((DoubleBuffer) record.buf).put(state.getPlaneEquations(planeIndex)); record.buf.flip(); - GL11.glClipPlane(GL11.GL_CLIP_PLANE0 + planeIndex, record.buf); + GL11.glClipPlane(GL11.GL_CLIP_PLANE0 + planeIndex, (DoubleBuffer) record.buf); } else { if (!record.isValid() || record.planeEnabled[planeIndex]) { |