From e8a5a1cbb988670ca206ab1ac633e19a91bfa478 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Wed, 2 Apr 2014 04:41:48 +0200 Subject: Bug 801: WIP 2/2 - Add color attribute; Switch Shader instead of branching in shader; Update attributes and uniforms manually, drop ShaderState; - Due to shader-switching, 'renderModes' are now local to Region, e.g. UIShape etc - Remove RegionRenderer.renderModes - VBORegion2P*: - Use simple 2x float matrix for orthogonal P+Mv - Cleanup shader --- .../classes/com/jogamp/opengl/util/PMVMatrix.java | 81 +++------------------- .../com/jogamp/opengl/util/glsl/ShaderProgram.java | 17 +++-- .../com/jogamp/opengl/util/glsl/ShaderState.java | 3 +- 3 files changed, 19 insertions(+), 82 deletions(-) (limited to 'src/jogl/classes/com/jogamp/opengl/util') diff --git a/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java b/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java index 44288256a..8f5beeebe 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java +++ b/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java @@ -686,61 +686,12 @@ public class PMVMatrix implements GLMatrixFunc { @Override public final void glOrthof(final float left, final float right, final float bottom, final float top, final float zNear, final float zFar) { - // Ortho matrix (Column Order): - // 2/dx 0 0 0 - // 0 2/dy 0 0 - // 0 0 2/dz 0 - // tx ty tz 1 - final float dx=right-left; - final float dy=top-bottom; - final float dz=zFar-zNear; - final float tx=-1.0f*(right+left)/dx; - final float ty=-1.0f*(top+bottom)/dy; - final float tz=-1.0f*(zFar+zNear)/dz; - - matrixOrtho[0+4*0] = 2.0f/dx; - matrixOrtho[1+4*1] = 2.0f/dy; - matrixOrtho[2+4*2] = -2.0f/dz; - matrixOrtho[0+4*3] = tx; - matrixOrtho[1+4*3] = ty; - matrixOrtho[2+4*3] = tz; - - glMultMatrixf(matrixOrtho, 0); + glMultMatrixf( FloatUtil.makeOrthof(matrixOrtho, 0, false, left, right, bottom, top, zNear, zFar), 0 ); } @Override public final void glFrustumf(final float left, final float right, final float bottom, final float top, final float zNear, final float zFar) { - if(zNear<=0.0f||zFar<0.0f) { - throw new GLException("GL_INVALID_VALUE: zNear and zFar must be positive, and zNear>0"); - } - if(left==right || top==bottom) { - throw new GLException("GL_INVALID_VALUE: top,bottom and left,right must not be equal"); - } - // Frustum matrix (Column Order): - // 2*zNear/dx 0 0 0 - // 0 2*zNear/dy 0 0 - // A B C -1 - // 0 0 D 0 - final float zNear2 = 2.0f*zNear; - final float dx=right-left; - final float dy=top-bottom; - final float dz=zFar-zNear; - final float A=(right+left)/dx; - final float B=(top+bottom)/dy; - final float C=-1.0f*(zFar+zNear)/dz; - final float D=-2.0f*(zFar*zNear)/dz; - - matrixFrustum[0+4*0] = zNear2/dx; - matrixFrustum[1+4*1] = zNear2/dy; - matrixFrustum[2+4*2] = C; - - matrixFrustum[0+4*2] = A; - matrixFrustum[1+4*2] = B; - - matrixFrustum[2+4*3] = D; - matrixFrustum[3+4*2] = -1.0f; - - glMultMatrixf(matrixFrustum, 0); + glMultMatrixf( FloatUtil.makeFrustumf(matrixFrustum, 0, false, left, right, bottom, top, zNear, zFar), 0 ); } // @@ -751,11 +702,7 @@ public class PMVMatrix implements GLMatrixFunc { * {@link #glMultMatrixf(FloatBuffer) Multiply} the {@link #glGetMatrixMode() current matrix} with the perspective/frustum matrix. */ public final void gluPerspective(final float fovy, final float aspect, final float zNear, final float zFar) { - float top=(float)Math.tan(fovy*((float)Math.PI)/360.0f)*zNear; - float bottom=-1.0f*top; - float left=aspect*bottom; - float right=aspect*top; - glFrustumf(left, right, bottom, top, zNear, zFar); + glMultMatrixf( FloatUtil.makePerspective(matrixFrustum, 0, false, fovy*((float)Math.PI)/360.0f, aspect, zNear, zFar), 0 ); } /** @@ -840,24 +787,12 @@ public class PMVMatrix implements GLMatrixFunc { * using a {@link AABBox#intersectsRay(Ray, float[]) bounding box}. *

* Notes for picking winz0 and winz1: + *

*

- *

- * Love Your Z-Buffer - *

-     *  delta = z * z / ( zNear * (1<<N) - z )
-     *
-     *  Where:
-     *    N     = number of bits of Z precision
-     *    zNear = distance from eye to near clip plane
-     *    z     = distance from the eye to the object
-     *    delta = the smallest resolvable Z separation at this range.
-     * 
- * Another equation to determine winZ for 'orthoDist' > 0 - *
-     *  winZ = (1f/zNear-1f/orthoDist)/(1f/zNear-1f/zFar);
-     * 
- *

- * * @param winx * @param winy * @param winz0 diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java index b289b41e2..6a4b13dfb 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java +++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java @@ -312,17 +312,20 @@ public class ShaderProgram { gl.glUseProgram( on ? shaderProgram : 0 ); programInUse = on; } + public synchronized void notifyNotInUse() { + programInUse = false; + } - protected boolean programLinked = false; - protected boolean programInUse = false; - protected int shaderProgram = 0; // non zero is valid! - protected HashSet allShaderCode = new HashSet(); - protected HashSet attachedShaderCode = new HashSet(); - protected int id = -1; + private boolean programLinked = false; + private boolean programInUse = false; + private int shaderProgram = 0; // non zero is valid! + private final HashSet allShaderCode = new HashSet(); + private final HashSet attachedShaderCode = new HashSet(); + private int id = -1; private static synchronized int getNextID() { return nextID++; } - protected static int nextID = 1; + private static int nextID = 1; } diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java index ce4c2615d..64dd589b8 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java +++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java @@ -176,8 +176,7 @@ public class ShaderState { } if(shaderProgram.inUse()) { if(null != prog && enable) { - // new program will issue glUseProgram(..) - shaderProgram.programInUse = false; + shaderProgram.notifyNotInUse(); } else { // no new 'enabled' program - disable useProgram(gl, false); -- cgit v1.2.3