summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2012-02-20 14:43:13 +0100
committerSven Gothel <[email protected]>2012-02-20 14:43:13 +0100
commitd97c54896d349e8a22c9cafec75c62476c16fdd1 (patch)
tree5a1c0e92632ac2b8488e69765a4c803730c4f6f4
parentcde4111c7be2613025ad7648e20087bc8634b4cb (diff)
Fix commit fb7165e690546359dee92dd60b04be69f141c87e; Clarify ShaderState.attachShaderProgram(..)
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java38
-rwxr-xr-xsrc/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java2
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java2
-rw-r--r--src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncPipeline.java8
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestFBOMRTNEWT01.java9
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLShaderState01NEWT.java10
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLShaderState02NEWT.java23
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestRulerNEWT01.java3
8 files changed, 38 insertions, 57 deletions
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 a276018d9..4b680b849 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java
@@ -197,27 +197,10 @@ public class ShaderState {
* as well as switching to another program on the fly,
* while managing all attribute and uniform data.</p>
*
- * <p>[Re]sets all data and use program in case of a program switch.<br>
+ * <p>[Re]sets all data and use program in case of a program switch.</p>
*
- * Use program if linked and if previous program was in use.</p>
- *
- * @throws GLException if program was not linked and linking fails
- */
- public synchronized void attachShaderProgram(GL2ES2 gl, ShaderProgram prog) throws GLException {
- attachShaderProgram(gl, prog, false);
- }
-
- /**
- * Attach or switch a shader program
- *
- * <p>Attaching a shader program the first time,
- * as well as switching to another program on the fly,
- * while managing all attribute and uniform data.</p>
- *
- * <p>[Re]sets all data and use program in case of a program switch.<br>
- *
- * Use program if linked and if previous program was in use,
- * or if <code>enable</code> is true.</p>
+ * <p>Use program, {@link #useProgram(GL2ES2, boolean)},
+ * if <code>enable</code> is <code>true</code>.</p>
*
* @throws GLException if program was not linked and linking fails
*/
@@ -227,7 +210,7 @@ public class ShaderState {
if(DEBUG) {
int curId = (null!=shaderProgram)?shaderProgram.id():-1;
int newId = (null!=prog)?prog.id():-1;
- System.err.println("Info: attachShaderProgram: "+curId+" -> "+newId+"\n\t"+shaderProgram+"\n\t"+prog);
+ System.err.println("Info: attachShaderProgram: "+curId+" -> "+newId+" (enable: "+enable+")\n\t"+shaderProgram+"\n\t"+prog);
if(verbose) {
Throwable tX = new Throwable("Info: attachShaderProgram: Trace");
tX.printStackTrace();
@@ -241,15 +224,12 @@ public class ShaderState {
}
return;
}
- prgInUse = shaderProgram.inUse();
-
- if(prgInUse) {
- // only disable if in use
- if(null != prog) {
+ if(shaderProgram.inUse()) {
+ if(null != prog && enable) {
// new program will issue glUseProgram(..)
shaderProgram.programInUse = false;
} else {
- // no new program - disable
+ // no new 'enabled' program - disable
useProgram(gl, false);
}
}
@@ -262,9 +242,9 @@ public class ShaderState {
if(null!=shaderProgram) {
// [re]set all data and use program if switching program,
// or use program if program is linked
- if(shaderProgram.linked() || resetAllShaderData) {
+ if(resetAllShaderData || enable) {
useProgram(gl, true); // may reset all data
- if(!prgInUse && !enable) {
+ if(!enable) {
useProgram(gl, false);
}
}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java b/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java
index 0217a6369..06499208f 100755
--- a/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java
@@ -66,7 +66,7 @@ public class RegionRendererImpl01 extends RegionRenderer {
sp.add(rsFp);
sp.init(gl);
- st.attachShaderProgram(gl, sp);
+ st.attachShaderProgram(gl, sp, false);
st.bindAttribLocation(gl, AttributeNames.VERTEX_ATTR_IDX, AttributeNames.VERTEX_ATTR_NAME);
st.bindAttribLocation(gl, AttributeNames.TEXCOORD_ATTR_IDX, AttributeNames.TEXCOORD_ATTR_NAME);
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java b/src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java
index 5ed3529bf..fa57b3468 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java
@@ -59,7 +59,7 @@ public class TextRendererImpl01 extends TextRenderer {
sp.add(rsFp);
sp.init(gl);
- st.attachShaderProgram(gl, sp);
+ st.attachShaderProgram(gl, sp, false);
st.bindAttribLocation(gl, AttributeNames.VERTEX_ATTR_IDX, AttributeNames.VERTEX_ATTR_NAME);
st.bindAttribLocation(gl, AttributeNames.TEXCOORD_ATTR_IDX, AttributeNames.TEXCOORD_ATTR_NAME);
diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncPipeline.java b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncPipeline.java
index 973bcc147..41a694e9e 100644
--- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncPipeline.java
+++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncPipeline.java
@@ -365,15 +365,15 @@ public class FixedFuncPipeline {
if(textureEnabled) {
if(lightingEnabled) {
- shaderState.attachShaderProgram(gl, shaderProgramColorTextureLight);
+ shaderState.attachShaderProgram(gl, shaderProgramColorTextureLight, true);
} else {
- shaderState.attachShaderProgram(gl, shaderProgramColorTexture);
+ shaderState.attachShaderProgram(gl, shaderProgramColorTexture, true);
}
} else {
if(lightingEnabled) {
- shaderState.attachShaderProgram(gl, shaderProgramColorLight);
+ shaderState.attachShaderProgram(gl, shaderProgramColorLight, true);
} else {
- shaderState.attachShaderProgram(gl, shaderProgramColor);
+ shaderState.attachShaderProgram(gl, shaderProgramColor, true);
}
}
if(DEBUG) {
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestFBOMRTNEWT01.java b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestFBOMRTNEWT01.java
index aca1e6607..5c9ec0d82 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestFBOMRTNEWT01.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestFBOMRTNEWT01.java
@@ -84,7 +84,7 @@ public class TestFBOMRTNEWT01 extends UITestCase {
Assert.assertTrue(!sp0.inUse());
Assert.assertTrue(!sp0.linked());
Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
- st.attachShaderProgram(gl, sp0);
+ st.attachShaderProgram(gl, sp0, false);
final ShaderCode vp1 = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, 1, RedSquareES2.class,
"shader", "shader/bin", "fbo-mrt-2");
@@ -97,8 +97,7 @@ public class TestFBOMRTNEWT01 extends UITestCase {
Assert.assertTrue(!sp1.inUse());
Assert.assertTrue(!sp1.linked());
Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
- st.attachShaderProgram(gl, sp1);
- st.useProgram(gl, true);
+ st.attachShaderProgram(gl, sp1, true);
final PMVMatrix pmvMatrix = new PMVMatrix();
final GLUniformData pmvMatrixUniform = new GLUniformData("gcu_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf());
@@ -175,7 +174,7 @@ public class TestFBOMRTNEWT01 extends UITestCase {
for(int i=0; i<durationPerTest; i+=50) {
// pass 1 - MRT: Red -> buffer0, Green -> buffer1
- st.attachShaderProgram(gl, sp0);
+ st.attachShaderProgram(gl, sp0, true);
vertices0.enableBuffer(gl, true);
colors0.enableBuffer(gl, true);
@@ -191,7 +190,7 @@ public class TestFBOMRTNEWT01 extends UITestCase {
// pass 2 - mix buffer0, buffer1 and blue
// rg = buffer0.rg + buffer1.rg, b = Blue - length(rg);
- st.attachShaderProgram(gl, sp1);
+ st.attachShaderProgram(gl, sp1, true);
vertices0.enableBuffer(gl, true);
colors0.enableBuffer(gl, true);
texCoords0.enableBuffer(gl, true);
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLShaderState01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLShaderState01NEWT.java
index ea290693c..037a973f5 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLShaderState01NEWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLShaderState01NEWT.java
@@ -88,7 +88,9 @@ public class TestGLSLShaderState01NEWT extends UITestCase {
Assert.assertTrue(!sp.linked());
Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
- st.attachShaderProgram(gl, sp);
+ st.attachShaderProgram(gl, sp, false);
+ Assert.assertTrue(!sp.inUse());
+ Assert.assertTrue(!sp.linked());
Assert.assertEquals(null, ShaderState.getShaderState(gl));
st.setShaderState(gl); // pre-use attach
@@ -211,8 +213,7 @@ public class TestGLSLShaderState01NEWT extends UITestCase {
sp.init(gl);
Assert.assertTrue(sp.link(gl, System.err));
- st.attachShaderProgram(gl, sp);
- st.useProgram(gl, true);
+ st.attachShaderProgram(gl, sp, true);
// setup mgl_PMVMatrix
final PMVMatrix pmvMatrix = new PMVMatrix();
@@ -300,8 +301,7 @@ public class TestGLSLShaderState01NEWT extends UITestCase {
sp.init(gl);
Assert.assertTrue(sp.link(gl, System.err));
- st.attachShaderProgram(gl, sp);
- st.useProgram(gl, true);
+ st.attachShaderProgram(gl, sp, true);
// setup mgl_PMVMatrix
final PMVMatrix pmvMatrix = new PMVMatrix();
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLShaderState02NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLShaderState02NEWT.java
index fb52ff04b..0efb63dca 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLShaderState02NEWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLShaderState02NEWT.java
@@ -114,7 +114,9 @@ public class TestGLSLShaderState02NEWT extends UITestCase {
Assert.assertTrue(!sp0.linked());
Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
- st.attachShaderProgram(gl, sp0);
+ st.attachShaderProgram(gl, sp0, false);
+ Assert.assertTrue(!sp0.inUse());
+ Assert.assertTrue(!sp0.linked());
Assert.assertEquals(null, ShaderState.getShaderState(gl));
st.setShaderState(gl); // pre-use attach
Assert.assertEquals(st, ShaderState.getShaderState(gl));
@@ -200,7 +202,9 @@ public class TestGLSLShaderState02NEWT extends UITestCase {
GLSLMiscHelper.displayVCArrays(drawable, gl, true, vertices1, colors1, true, 4, durationPerTest);
// SP1
- st.attachShaderProgram(gl, sp1);
+ st.attachShaderProgram(gl, sp1, true);
+ Assert.assertTrue(sp1.inUse());
+ Assert.assertTrue(sp1.linked());
if(!linkSP1) {
// all attribute locations shall be same now, due to impl. glBindAttributeLocation
@@ -267,8 +271,7 @@ public class TestGLSLShaderState02NEWT extends UITestCase {
sp0.init(gl);
Assert.assertTrue(sp0.link(gl, System.err));
- st.attachShaderProgram(gl, sp0);
- st.useProgram(gl, true);
+ st.attachShaderProgram(gl, sp0, true);
// setup mgl_PMVMatrix
final PMVMatrix pmvMatrix = new PMVMatrix();
@@ -313,20 +316,20 @@ public class TestGLSLShaderState02NEWT extends UITestCase {
gl.setSwapInterval(0);
// validation ..
- st.attachShaderProgram(gl, sp0);
+ st.attachShaderProgram(gl, sp0, true);
GLSLMiscHelper.displayVCArrays(drawable, gl, true, vertices0, colors0, true, 1, 0);
GLSLMiscHelper.displayVCArrays(drawable, gl, true, vertices1, colors1, true, 2, 0);
- st.attachShaderProgram(gl, sp1);
+ st.attachShaderProgram(gl, sp1, true);
GLSLMiscHelper.displayVCArrays(drawable, gl, true, vertices0, colors0, true, 1, 0);
GLSLMiscHelper.displayVCArrays(drawable, gl, true, vertices1, colors1, true, 2, 0);
// warmup ..
for(int frames=0; frames<GLSLMiscHelper.frames_warmup; frames+=2) {
// SP0
- st.attachShaderProgram(gl, sp0);
+ st.attachShaderProgram(gl, sp0, true);
GLSLMiscHelper.displayVCArraysNoChecks(drawable, gl, true, vertices0, colors0, true);
// SP1
- st.attachShaderProgram(gl, sp1);
+ st.attachShaderProgram(gl, sp1, true);
GLSLMiscHelper.displayVCArraysNoChecks(drawable, gl, true, vertices1, colors1, true);
}
@@ -336,11 +339,11 @@ public class TestGLSLShaderState02NEWT extends UITestCase {
for(frames=0; frames<GLSLMiscHelper.frames_perftest; frames+=4) {
// SP0
- st.attachShaderProgram(gl, sp0);
+ st.attachShaderProgram(gl, sp0, true);
GLSLMiscHelper.displayVCArraysNoChecks(drawable, gl, true, vertices0, colors0, true);
GLSLMiscHelper.displayVCArraysNoChecks(drawable, gl, true, vertices1, colors1, true);
// SP1
- st.attachShaderProgram(gl, sp1);
+ st.attachShaderProgram(gl, sp1, true);
GLSLMiscHelper.displayVCArraysNoChecks(drawable, gl, true, vertices0, colors0, true);
GLSLMiscHelper.displayVCArraysNoChecks(drawable, gl, true, vertices1, colors1, true);
}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestRulerNEWT01.java b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestRulerNEWT01.java
index 13780a7e5..12122cffc 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestRulerNEWT01.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestRulerNEWT01.java
@@ -85,8 +85,7 @@ public class TestRulerNEWT01 extends UITestCase {
Assert.assertTrue(!sp0.linked());
Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
- st.attachShaderProgram(gl, sp0);
- st.useProgram(gl, true);
+ st.attachShaderProgram(gl, sp0, true);
final PMVMatrix pmvMatrix = new PMVMatrix();
final GLUniformData pmvMatrixUniform = new GLUniformData("gcu_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf());