diff options
author | Sven Gothel <[email protected]> | 2012-10-22 21:28:40 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-10-22 21:28:40 +0200 |
commit | 03cdffe5739ef8b032638cf4169e713c90fb36c6 (patch) | |
tree | 0728e1bf17f11acf824cca7e76e2a96d5d87d9ae | |
parent | 5bdd283a9c3d0c656c859d499476173e2f609839 (diff) |
FixedFuncHook/ImmModeSink: Fix *Pointer 'normalized' parameter
All *Pointer methods used 'normalized:=false', but we cannot assume
the fixed function code does use normalized (0f..1f) values.
On the contrary, it usually uses the native format value range.
Hence we have to pass normalized:=true for all fixed point data types
and normalized:=false for floating point data types.
5 files changed, 48 insertions, 26 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataWrapper.java b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataWrapper.java index bade0a3ae..f4a197be1 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataWrapper.java +++ b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataWrapper.java @@ -253,16 +253,10 @@ public class GLArrayDataWrapper implements GLArrayData { this.componentType = componentType; componentClazz = getBufferClass(componentType); - switch(componentType) { - case GL.GL_BYTE: - case GL.GL_UNSIGNED_BYTE: - case GL.GL_SHORT: - case GL.GL_UNSIGNED_SHORT: - case GL.GL_FIXED: - this.normalized = normalized; - break; - default: - this.normalized = false; + if( GLBuffers.isGLTypeFixedPoint(componentType) ) { + this.normalized = normalized; + } else { + this.normalized = false; } componentByteSize = GLBuffers.sizeOfGLType(componentType); if(0 > componentByteSize) { diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLBuffers.java b/src/jogl/classes/com/jogamp/opengl/util/GLBuffers.java index 10d59bf7d..174935dcc 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/GLBuffers.java +++ b/src/jogl/classes/com/jogamp/opengl/util/GLBuffers.java @@ -78,6 +78,27 @@ public class GLBuffers extends Buffers { } /** + * @param glType GL primitive type + * @return false if one of GL primitive floating point types, otherwise true + * GL_FLOAT, <br/> + * GL_HALF_FLOAT, <br/> + * GL_HALF_FLOAT_OES, <br/> + * GL_DOUBLE <br/> + */ + public static final boolean isGLTypeFixedPoint(int glType) { + switch(glType) { + case GL.GL_FLOAT: + case GL.GL_HALF_FLOAT: + case GLES2.GL_HALF_FLOAT_OES: + case GL2GL3.GL_DOUBLE: + return false; + + default: + return true; + } + } + + /** * @param glType shall be one of (29) <br/> * GL_BYTE, GL_UNSIGNED_BYTE, <br/> * GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV, <br/> diff --git a/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java b/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java index fca7ee6ae..300e2b615 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java +++ b/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java @@ -1137,25 +1137,29 @@ public class ImmModeSink { buffer.flip(); if(vComps>0) { - vArrayData = GLArrayDataWrapper.createFixed(GLPointerFunc.GL_VERTEX_ARRAY, vComps, vDataType, false, 0, + vArrayData = GLArrayDataWrapper.createFixed(GLPointerFunc.GL_VERTEX_ARRAY, vComps, + vDataType, GLBuffers.isGLTypeFixedPoint(vDataType), 0, vertexArray, 0, vOffset, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER); } else { vArrayData = null; } if(cComps>0) { - cArrayData = GLArrayDataWrapper.createFixed(GLPointerFunc.GL_COLOR_ARRAY, cComps, cDataType, false, 0, + cArrayData = GLArrayDataWrapper.createFixed(GLPointerFunc.GL_COLOR_ARRAY, cComps, + cDataType, GLBuffers.isGLTypeFixedPoint(cDataType), 0, colorArray, 0, cOffset, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER); } else { cArrayData = null; } if(nComps>0) { - nArrayData = GLArrayDataWrapper.createFixed(GLPointerFunc.GL_NORMAL_ARRAY, nComps, nDataType, false, 0, + nArrayData = GLArrayDataWrapper.createFixed(GLPointerFunc.GL_NORMAL_ARRAY, nComps, + nDataType, GLBuffers.isGLTypeFixedPoint(nDataType), 0, normalArray, 0, nOffset, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER); } else { nArrayData = null; } if(tComps>0) { - tArrayData = GLArrayDataWrapper.createFixed(GLPointerFunc.GL_TEXTURE_COORD_ARRAY, tComps, tDataType, false, 0, + tArrayData = GLArrayDataWrapper.createFixed(GLPointerFunc.GL_TEXTURE_COORD_ARRAY, tComps, + tDataType, GLBuffers.isGLTypeFixedPoint(tDataType), 0, textCoordArray, 0, tOffset, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER); } else { tArrayData = null; diff --git a/src/jogl/classes/javax/media/opengl/GLArrayData.java b/src/jogl/classes/javax/media/opengl/GLArrayData.java index 7c56b53cb..5d17f6874 100644 --- a/src/jogl/classes/javax/media/opengl/GLArrayData.java +++ b/src/jogl/classes/javax/media/opengl/GLArrayData.java @@ -145,7 +145,11 @@ public interface GLArrayData { /** * True, if GL shall normalize fixed point data while converting - * them into float + * them into float. + * <p> + * Default behavior (of the fixed function pipeline) is <code>true</code> + * for fixed point data type and <code>false</code> for floating point data types. + * </p> */ public boolean getNormalized(); diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java index 43abfe5ef..351d7a110 100644 --- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java @@ -30,12 +30,9 @@ package jogamp.opengl.util.glsl.fixedfunc; import java.nio.Buffer; -import java.nio.ByteBuffer; import java.nio.IntBuffer; -import java.nio.ShortBuffer; import javax.media.opengl.GL; -import javax.media.opengl.GL2; import javax.media.opengl.GL2ES2; import javax.media.opengl.GLArrayData; import javax.media.opengl.GLException; @@ -343,14 +340,15 @@ public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFun } public void glVertexPointer(int size, int type, int stride, java.nio.Buffer pointer) { - glVertexPointer(GLArrayDataWrapper.createFixed(GL_VERTEX_ARRAY, size, type, false, stride, pointer, 0, 0, 0, GL.GL_ARRAY_BUFFER)); + glVertexPointer(GLArrayDataWrapper.createFixed(GL_VERTEX_ARRAY, size, type, GLBuffers.isGLTypeFixedPoint(type), stride, + pointer, 0, 0, 0, GL.GL_ARRAY_BUFFER)); } public void glVertexPointer(int size, int type, int stride, long pointer_buffer_offset) { int vboName = gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER); if(vboName==0) { throw new GLException("no GL_ARRAY_BUFFER VBO bound"); } - glVertexPointer(GLArrayDataWrapper.createFixed(GL_VERTEX_ARRAY, size, type, false, stride, + glVertexPointer(GLArrayDataWrapper.createFixed(GL_VERTEX_ARRAY, size, type, GLBuffers.isGLTypeFixedPoint(type), stride, null, vboName, pointer_buffer_offset, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER)); } @@ -370,7 +368,7 @@ public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFun fixedFunction.glColorPointer(gl, array); } public void glColorPointer(int size, int type, int stride, java.nio.Buffer pointer) { - glColorPointer(GLArrayDataWrapper.createFixed(GL_COLOR_ARRAY, size, type, false, stride, + glColorPointer(GLArrayDataWrapper.createFixed(GL_COLOR_ARRAY, size, type, GLBuffers.isGLTypeFixedPoint(type), stride, pointer, 0, 0, 0, GL.GL_ARRAY_BUFFER)); } public void glColorPointer(int size, int type, int stride, long pointer_buffer_offset) { @@ -378,7 +376,7 @@ public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFun if(vboName==0) { throw new GLException("no GL_ARRAY_BUFFER VBO bound"); } - glColorPointer(GLArrayDataWrapper.createFixed(GL_COLOR_ARRAY, size, type, false, stride, + glColorPointer(GLArrayDataWrapper.createFixed(GL_COLOR_ARRAY, size, type, GLBuffers.isGLTypeFixedPoint(type), stride, null, vboName, pointer_buffer_offset, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER)); } @@ -401,7 +399,7 @@ public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFun fixedFunction.glNormalPointer(gl, array); } public void glNormalPointer(int type, int stride, java.nio.Buffer pointer) { - glNormalPointer(GLArrayDataWrapper.createFixed(GL_NORMAL_ARRAY, 3, type, false, stride, + glNormalPointer(GLArrayDataWrapper.createFixed(GL_NORMAL_ARRAY, 3, type, GLBuffers.isGLTypeFixedPoint(type), stride, pointer, 0, 0, 0, GL.GL_ARRAY_BUFFER)); } public void glNormalPointer(int type, int stride, long pointer_buffer_offset) { @@ -409,7 +407,7 @@ public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFun if(vboName==0) { throw new GLException("no GL_ARRAY_BUFFER VBO bound"); } - glNormalPointer(GLArrayDataWrapper.createFixed(GL_NORMAL_ARRAY, 3, type, false, stride, + glNormalPointer(GLArrayDataWrapper.createFixed(GL_NORMAL_ARRAY, 3, type, GLBuffers.isGLTypeFixedPoint(type), stride, null, vboName, pointer_buffer_offset, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER)); } @@ -430,7 +428,8 @@ public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFun } public void glTexCoordPointer(int size, int type, int stride, java.nio.Buffer pointer) { glTexCoordPointer( - GLArrayDataWrapper.createFixed(GL_TEXTURE_COORD_ARRAY, size, type, false, stride, pointer, 0, 0, 0, GL.GL_ARRAY_BUFFER)); + GLArrayDataWrapper.createFixed(GL_TEXTURE_COORD_ARRAY, size, type, GLBuffers.isGLTypeFixedPoint(type), stride, + pointer, 0, 0, 0, GL.GL_ARRAY_BUFFER)); } public void glTexCoordPointer(int size, int type, int stride, long pointer_buffer_offset) { int vboName = gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER); @@ -438,7 +437,7 @@ public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFun throw new GLException("no GL_ARRAY_BUFFER VBO bound"); } glTexCoordPointer( - GLArrayDataWrapper.createFixed(GL_TEXTURE_COORD_ARRAY, size, type, false, stride, + GLArrayDataWrapper.createFixed(GL_TEXTURE_COORD_ARRAY, size, type, GLBuffers.isGLTypeFixedPoint(type), stride, null, vboName, pointer_buffer_offset, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER) ); } |