summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.classpath2
-rw-r--r--.externalToolBuilders/jogl-demos builder.launch9
-rw-r--r--make/build.xml2
-rw-r--r--src/demos/dualDepthPeeling/DualDepthPeeling.java386
-rw-r--r--src/demos/dualDepthPeeling/GLHelper.java53
-rw-r--r--src/demos/dualDepthPeeling/GLSLProgramObject.java283
-rw-r--r--src/demos/dualDepthPeeling/Model.java4
7 files changed, 277 insertions, 462 deletions
diff --git a/.classpath b/.classpath
index e48d8bf..48e7829 100644
--- a/.classpath
+++ b/.classpath
@@ -6,7 +6,7 @@
<classpathentry kind="src" path="src/redbook/src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/Ant"/>
- <classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/jogamp"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/SWT"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/jogamp"/>
<classpathentry kind="output" path="build"/>
</classpath>
diff --git a/.externalToolBuilders/jogl-demos builder.launch b/.externalToolBuilders/jogl-demos builder.launch
index 18e6f94..433ad72 100644
--- a/.externalToolBuilders/jogl-demos builder.launch
+++ b/.externalToolBuilders/jogl-demos builder.launch
@@ -5,12 +5,21 @@
<booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/>
<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/>
<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${project}"/>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
+<listEntry value="/jogl-demos"/>
+</listAttribute>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
+<listEntry value="4"/>
+</listAttribute>
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/>
+<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.ant.internal.launching.remote.InternalAntRunner"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="jogl-demos"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/jogl-demos/make/build.xml}"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,"/>
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${workspace_loc:/jogl-demos/make}"/>
+<stringAttribute key="process_factory_id" value="org.eclipse.ant.ui.remoteAntProcessFactory"/>
</launchConfiguration>
diff --git a/make/build.xml b/make/build.xml
index 0a2a4f9..d8edeaa 100644
--- a/make/build.xml
+++ b/make/build.xml
@@ -196,6 +196,8 @@
<include name="demos/es2/perftst/shader/**" />
<include name="demos/es2/perftst/data/**" />
<include name="demos/es2/openmax/shader/**" />
+ <include name="demos/dualDepthPeeling/shader/*" />
+ <include name="demos/dualDepthPeeling/media/models/*" />
</fileset>
<!-- Avoid requiring dependence on huge jogl-demos-data.jar for
particle engine demo -->
diff --git a/src/demos/dualDepthPeeling/DualDepthPeeling.java b/src/demos/dualDepthPeeling/DualDepthPeeling.java
index 4d4657e..9cc4b05 100644
--- a/src/demos/dualDepthPeeling/DualDepthPeeling.java
+++ b/src/demos/dualDepthPeeling/DualDepthPeeling.java
@@ -8,12 +8,9 @@ import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
+import java.nio.FloatBuffer;
-import javax.media.opengl.GL;
-import javax.media.opengl.GL2;
import javax.media.opengl.*;
-import javax.media.opengl.GLAutoDrawable;
-import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLCanvas;
import javax.media.opengl.glu.GLU;
@@ -22,6 +19,9 @@ import javax.media.opengl.GLEventListener;
import com.jogamp.common.nio.Buffers;
import com.jogamp.opengl.util.*;
+import com.jogamp.opengl.util.glsl.ShaderCode;
+import com.jogamp.opengl.util.glsl.ShaderProgram;
+import com.jogamp.opengl.util.glsl.ShaderState;
// Translated from C++ Version see below:
//--------------------------------------------------------------------------------------
@@ -65,26 +65,45 @@ public class DualDepthPeeling implements GLEventListener, KeyListener, MouseList
public boolean g_useOQ = true;
public int[] g_queryId = new int[1];
- public String MODEL_FILENAME = new String( "demos/dualDepthPeeling/media/models/dragon.obj" );
- public String SHADER_PATH = new String( "src/dual_depth_peeling/shaders/" );
+ public String MODEL_FILENAME = new String( "media/models/dragon.obj" );
- public GLSLProgramObject g_shaderDualInit;
- public GLSLProgramObject g_shaderDualPeel;
- public GLSLProgramObject g_shaderDualBlend;
- public GLSLProgramObject g_shaderDualFinal;
-
- public GLSLProgramObject g_shaderFrontInit;
- public GLSLProgramObject g_shaderFrontPeel;
- public GLSLProgramObject g_shaderFrontBlend;
- public GLSLProgramObject g_shaderFrontFinal;
-
- public GLSLProgramObject g_shaderAverageInit;
- public GLSLProgramObject g_shaderAverageFinal;
-
- public GLSLProgramObject g_shaderWeightedSumInit;
- public GLSLProgramObject g_shaderWeightedSumFinal;
-
- public float[] g_opacity = new float[]{0.6f};
+ public static final String s_FrontBlenderTex = "FrontBlenderTex";
+ public static final String s_BackBlenderTex = "BackBlenderTex";
+ public static final String s_DepthBlenderTex = "DepthBlenderTex";
+ public static final String s_ColorTex = "ColorTex";
+ public static final String s_ColorTex0 = "ColorTex0";
+ public static final String s_ColorTex1 = "ColorTex1";
+ public static final String s_TempTex = "TempTex";
+ public static final String s_BackgroundColor = "BackgroundColor";
+
+ public GLUniformData g_FrontBlenderTexUnit;
+ public GLUniformData g_BackBlenderTexUnit;
+ public GLUniformData g_DepthBlenderTexUnit;
+ public GLUniformData g_ColorTexUnit;
+ public GLUniformData g_ColorTex0Unit;
+ public GLUniformData g_ColorTex1Unit;
+ public GLUniformData g_TempTexUnit;
+ public GLUniformData g_AlphaUni;
+ public GLUniformData g_backgroundColorUni;
+
+ public ShaderState g_shaderState;
+ public ShaderProgram g_shaderDualInit;
+ public ShaderProgram g_shaderDualPeel;
+ public ShaderProgram g_shaderDualBlend;
+ public ShaderProgram g_shaderDualFinal;
+
+ public ShaderProgram g_shaderFrontInit;
+ public ShaderProgram g_shaderFrontPeel;
+ public ShaderProgram g_shaderFrontBlend;
+ public ShaderProgram g_shaderFrontFinal;
+
+ public ShaderProgram g_shaderAverageInit;
+ public ShaderProgram g_shaderAverageFinal;
+
+ public ShaderProgram g_shaderWeightedSumInit;
+ public ShaderProgram g_shaderWeightedSumFinal;
+
+ public float g_opacity = 0.6f;
public char g_mode = DUAL_PEELING_MODE;
public boolean g_showOsd = true;
public boolean g_bShowUI = true;
@@ -100,9 +119,9 @@ public class DualDepthPeeling implements GLEventListener, KeyListener, MouseList
public float[] g_rot = new float[]{0.0f, 45.0f};
public float[] g_pos = new float[]{0.0f, 0.0f, 2.0f};
- float[] g_white = new float[]{1.0f,1.0f,1.0f};
- float[] g_black = new float[]{0.0f};
- float[] g_backgroundColor = g_white;
+ static final FloatBuffer g_white = Buffers.newDirectFloatBuffer(new float[]{1.0f,1.0f,1.0f});
+ static final FloatBuffer g_black = Buffers.newDirectFloatBuffer(new float[]{0.0f,0.0f,0.0f});
+ FloatBuffer g_backgroundColor = g_white;
public int[] g_dualBackBlenderFboId = new int[1];
public int[] g_dualPeelingSingleFboId = new int[1];
@@ -128,6 +147,8 @@ public class DualDepthPeeling implements GLEventListener, KeyListener, MouseList
GL2.GL_COLOR_ATTACHMENT5,
GL2.GL_COLOR_ATTACHMENT6
};
+
+ boolean reloadShaders = false;
public DualDepthPeeling()
{
@@ -405,85 +426,89 @@ public class DualDepthPeeling implements GLEventListener, KeyListener, MouseList
return m_kCanvas;
}
+ ShaderProgram build(GL2ES2 gl, String basename, boolean link) {
+ ShaderProgram sp = new ShaderProgram();
+ ShaderCode vp = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, 1, DualDepthPeeling.class,
+ "shader", null, basename);
+ ShaderCode fp = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, 1, DualDepthPeeling.class,
+ "shader", null, basename);
+ sp.add(vp);
+ sp.add(fp);
+ if(link && !sp.link(gl, System.err)) {
+ throw new GLException("Couldn't link program: "+sp);
+ }
+ return sp;
+ }
+ ShaderProgram build(GL2ES2 gl, String[] basenames, boolean link) {
+ ShaderProgram sp = new ShaderProgram();
+ ShaderCode vp = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, basenames.length, DualDepthPeeling.class,
+ "shader", basenames, null, null);
+ sp.add(vp);
+ ShaderCode fp = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, basenames.length, DualDepthPeeling.class,
+ "shader", basenames, null, null);
+ sp.add(fp);
+ if(link && !sp.link(gl, System.err)) {
+ throw new GLException("Couldn't link program: "+sp);
+ }
+ return sp;
+ }
+
//--------------------------------------------------------------------------
void BuildShaders(GL2 gl)
{
System.err.println("\nloading shaders...\n");
- g_shaderDualInit = new GLSLProgramObject();
- g_shaderDualInit.attachVertexShader(gl, "dual_peeling_init_vertex.glsl");
- g_shaderDualInit.attachFragmentShader(gl, "dual_peeling_init_fragment.glsl");
- g_shaderDualInit.link(gl);
-
- g_shaderDualPeel = new GLSLProgramObject();
- g_shaderDualPeel.attachVertexShader(gl, "shade_vertex.glsl");
- g_shaderDualPeel.attachVertexShader(gl, "dual_peeling_peel_vertex.glsl");
- g_shaderDualPeel.attachFragmentShader(gl, "shade_fragment.glsl");
- g_shaderDualPeel.attachFragmentShader(gl, "dual_peeling_peel_fragment.glsl");
- g_shaderDualPeel.link(gl);
-
- g_shaderDualBlend = new GLSLProgramObject();
- g_shaderDualBlend.attachVertexShader(gl, "dual_peeling_blend_vertex.glsl");
- g_shaderDualBlend.attachFragmentShader(gl, "dual_peeling_blend_fragment.glsl");
- g_shaderDualBlend.link(gl);
-
- g_shaderDualFinal = new GLSLProgramObject();
- g_shaderDualFinal.attachVertexShader(gl, "dual_peeling_final_vertex.glsl");
- g_shaderDualFinal.attachFragmentShader(gl, "dual_peeling_final_fragment.glsl");
- g_shaderDualFinal.link(gl);
-
- g_shaderFrontInit = new GLSLProgramObject();
- g_shaderFrontInit.attachVertexShader(gl, "shade_vertex.glsl");
- g_shaderFrontInit.attachVertexShader(gl, "front_peeling_init_vertex.glsl");
- g_shaderFrontInit.attachFragmentShader(gl, "shade_fragment.glsl");
- g_shaderFrontInit.attachFragmentShader(gl, "front_peeling_init_fragment.glsl");
- g_shaderFrontInit.link(gl);
-
- g_shaderFrontPeel = new GLSLProgramObject();
- g_shaderFrontPeel.attachVertexShader(gl, "shade_vertex.glsl");
- g_shaderFrontPeel.attachVertexShader(gl, "front_peeling_peel_vertex.glsl");
- g_shaderFrontPeel.attachFragmentShader(gl, "shade_fragment.glsl");
- g_shaderFrontPeel.attachFragmentShader(gl, "front_peeling_peel_fragment.glsl");
- g_shaderFrontPeel.link(gl);
-
- g_shaderFrontBlend = new GLSLProgramObject();
- g_shaderFrontBlend.attachVertexShader(gl, "front_peeling_blend_vertex.glsl");
- g_shaderFrontBlend.attachFragmentShader(gl, "front_peeling_blend_fragment.glsl");
- g_shaderFrontBlend.link(gl);
-
- g_shaderFrontFinal = new GLSLProgramObject();
- g_shaderFrontFinal.attachVertexShader(gl, "front_peeling_final_vertex.glsl");
- g_shaderFrontFinal.attachFragmentShader(gl, "front_peeling_final_fragment.glsl");
- g_shaderFrontFinal.link(gl);
-
- g_shaderAverageInit = new GLSLProgramObject();
- g_shaderAverageInit.attachVertexShader(gl, "shade_vertex.glsl");
- g_shaderAverageInit.attachVertexShader(gl, "wavg_init_vertex.glsl");
- g_shaderAverageInit.attachFragmentShader(gl, "shade_fragment.glsl");
- g_shaderAverageInit.attachFragmentShader(gl, "wavg_init_fragment.glsl");
- g_shaderAverageInit.link(gl);
-
- g_shaderAverageFinal = new GLSLProgramObject();
- g_shaderAverageFinal.attachVertexShader(gl, "wavg_final_vertex.glsl");
- g_shaderAverageFinal.attachFragmentShader(gl, "wavg_final_fragment.glsl");
- g_shaderAverageFinal.link(gl);
-
- g_shaderWeightedSumInit = new GLSLProgramObject();
- g_shaderWeightedSumInit.attachVertexShader(gl, "shade_vertex.glsl");
- g_shaderWeightedSumInit.attachVertexShader(gl, "wsum_init_vertex.glsl");
- g_shaderWeightedSumInit.attachFragmentShader(gl, "shade_fragment.glsl");
- g_shaderWeightedSumInit.attachFragmentShader(gl, "wsum_init_fragment.glsl");
- g_shaderWeightedSumInit.link(gl);
-
- g_shaderWeightedSumFinal = new GLSLProgramObject();
- g_shaderWeightedSumFinal.attachVertexShader(gl, "wsum_final_vertex.glsl");
- g_shaderWeightedSumFinal.attachFragmentShader(gl, "wsum_final_fragment.glsl");
- g_shaderWeightedSumFinal.link(gl);
+ g_shaderState = new ShaderState();
+ // g_shaderState.setVerbose(true);
+
+ g_shaderDualInit = build(gl, "dual_peeling_init", true);
+ g_shaderDualPeel = build(gl, new String[] { "shade", "dual_peeling_peel" }, true);
+ g_shaderDualBlend = build(gl, "dual_peeling_blend", true);
+ g_shaderDualFinal = build(gl, "dual_peeling_final", true);
+
+ g_shaderFrontInit = build(gl, new String[] { "shade", "front_peeling_init" }, true);
+ g_shaderFrontPeel = build(gl, new String[] { "shade", "front_peeling_peel" }, true);
+ g_shaderFrontBlend = build(gl, "front_peeling_blend", true);
+ g_shaderFrontFinal = build(gl, "front_peeling_final", true);
+
+ g_shaderAverageInit = build(gl, new String[] { "shade", "wavg_init" }, true);
+ g_shaderAverageFinal = build(gl, "wavg_final", true);
+
+ g_shaderWeightedSumInit = build(gl, new String[] { "shade", "wsum_init" }, true);
+ g_shaderWeightedSumFinal = build(gl, "wsum_final", true);
+
+ g_DepthBlenderTexUnit = new GLUniformData(s_DepthBlenderTex, 0);
+ g_shaderState.ownUniform(g_DepthBlenderTexUnit);
+
+ g_FrontBlenderTexUnit = new GLUniformData(s_FrontBlenderTex, 1);
+ g_shaderState.ownUniform(g_FrontBlenderTexUnit);
+
+ g_BackBlenderTexUnit = new GLUniformData(s_BackBlenderTex, 2);
+ g_shaderState.ownUniform(g_BackBlenderTexUnit);
+
+ g_TempTexUnit = new GLUniformData(s_TempTex, 0);
+ g_shaderState.ownUniform(g_TempTexUnit);
+
+ g_AlphaUni = new GLUniformData("Alpha", g_opacity);
+ g_shaderState.ownUniform(g_AlphaUni);
+
+ g_backgroundColorUni = new GLUniformData(s_BackgroundColor, 3, g_backgroundColor);
+ g_shaderState.ownUniform(g_backgroundColorUni);
+
+ g_ColorTexUnit = new GLUniformData(s_ColorTex, 0);
+ g_shaderState.ownUniform(g_ColorTexUnit);
+
+ g_ColorTex0Unit = new GLUniformData(s_ColorTex0, 0);
+ g_shaderState.ownUniform(g_ColorTex0Unit);
+
+ g_ColorTex1Unit = new GLUniformData(s_ColorTex1, 1);
+ g_shaderState.ownUniform(g_ColorTex1Unit);
}
//--------------------------------------------------------------------------
void DestroyShaders(GL2 gl)
{
+ g_shaderState.release(gl, false, false, false);
g_shaderDualInit.destroy(gl);
g_shaderDualPeel.destroy(gl);
g_shaderDualBlend.destroy(gl);
@@ -511,9 +536,6 @@ public class DualDepthPeeling implements GLEventListener, KeyListener, MouseList
/** GLCanvas for Java/JOGL */
private GLCanvas m_kCanvas;
- /** GL object from GLCanvas.getGL() used to access openGL calls. */
- private GL2 m_kGL = null;
-
void InitGL()
{
@@ -553,9 +575,9 @@ public class DualDepthPeeling implements GLEventListener, KeyListener, MouseList
gl.glClear(GL2.GL_COLOR_BUFFER_BIT);
gl.glBlendEquation(GL2.GL_MAX);
- g_shaderDualInit.bind(gl);
+ g_shaderState.attachShaderProgram(gl, g_shaderDualInit, true);
DrawModel(gl);
- g_shaderDualInit.unbind(gl);
+ g_shaderState.useProgram(gl, false);
// ---------------------------------------------------------------------
// 2. Dual Depth Peeling + Blending
@@ -565,7 +587,7 @@ public class DualDepthPeeling implements GLEventListener, KeyListener, MouseList
// we use another render target to do the alpha blending
//glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, g_dualBackBlenderFboId);
gl.glDrawBuffer(g_drawBuffers[6]);
- gl.glClearColor(g_backgroundColor[0], g_backgroundColor[1], g_backgroundColor[2], 0);
+ gl.glClearColor(g_backgroundColor.get(0), g_backgroundColor.get(1), g_backgroundColor.get(2), 0);
gl.glClear(GL2.GL_COLOR_BUFFER_BIT);
int currId = 0;
@@ -591,12 +613,14 @@ public class DualDepthPeeling implements GLEventListener, KeyListener, MouseList
gl.glDrawBuffers(3, g_drawBuffers, bufId+0);
gl.glBlendEquation(GL2.GL_MAX);
- g_shaderDualPeel.bind(gl);
- g_shaderDualPeel.bindTextureRECT(gl,"DepthBlenderTex", g_dualDepthTexId[prevId], 0);
- g_shaderDualPeel.bindTextureRECT(gl,"FrontBlenderTex", g_dualFrontBlenderTexId[prevId], 1);
- g_shaderDualPeel.setUniform(gl,"Alpha", g_opacity, 1);
+ // uses g_DepthBlenderTexUnit
+ // uses g_FrontBlenderTexUnit
+ // uses g_AlphaUni
+ g_shaderState.attachShaderProgram(gl, g_shaderDualPeel, true);
+ GLHelper.bindTextureRECT(gl, g_dualDepthTexId[prevId], g_DepthBlenderTexUnit.intValue());
+ GLHelper.bindTextureRECT(gl, g_dualFrontBlenderTexId[prevId], g_FrontBlenderTexUnit.intValue());
DrawModel(gl);
- g_shaderDualPeel.unbind(gl);
+ g_shaderState.useProgram(gl, false);
// Full screen pass to alpha-blend the back color
gl.glDrawBuffer(g_drawBuffers[6]);
@@ -608,10 +632,11 @@ public class DualDepthPeeling implements GLEventListener, KeyListener, MouseList
gl.glBeginQuery(GL2.GL_SAMPLES_PASSED, g_queryId[0]);
}
- g_shaderDualBlend.bind(gl);
- g_shaderDualBlend.bindTextureRECT(gl,"TempTex", g_dualBackTempTexId[currId], 0);
+ g_TempTexUnit.setData(0);
+ g_shaderState.attachShaderProgram(gl, g_shaderDualBlend, true);
+ GLHelper.bindTextureRECT(gl, g_dualBackTempTexId[currId], g_TempTexUnit.intValue());
gl.glCallList(g_quadDisplayList);
- g_shaderDualBlend.unbind(gl);
+ g_shaderState.useProgram(gl, false);
if (g_useOQ) {
gl.glEndQuery(GL2.GL_SAMPLES_PASSED);
@@ -632,11 +657,13 @@ public class DualDepthPeeling implements GLEventListener, KeyListener, MouseList
gl.glBindFramebuffer(GL2.GL_FRAMEBUFFER, 0);
gl.glDrawBuffer(GL2.GL_BACK);
- g_shaderDualFinal.bind(gl);
- g_shaderDualFinal.bindTextureRECT(gl,"FrontBlenderTex", g_dualFrontBlenderTexId[currId], 1);
- g_shaderDualFinal.bindTextureRECT(gl,"BackBlenderTex", g_dualBackBlenderTexId[0], 2);
+ // use g_FrontBlenderTexUnit
+ // use g_BackBlenderTexUnit
+ g_shaderState.attachShaderProgram(gl, g_shaderDualFinal, true);
+ GLHelper.bindTextureRECT(gl, g_dualFrontBlenderTexId[currId], g_FrontBlenderTexUnit.intValue());
+ GLHelper.bindTextureRECT(gl, g_dualBackBlenderTexId[0], g_BackBlenderTexUnit.intValue());
gl.glCallList(g_quadDisplayList);
- g_shaderDualFinal.unbind(gl);
+ g_shaderState.useProgram(gl, false);
}
//--------------------------------------------------------------------------
@@ -654,10 +681,10 @@ public class DualDepthPeeling implements GLEventListener, KeyListener, MouseList
gl.glEnable(GL2.GL_DEPTH_TEST);
- g_shaderFrontInit.bind(gl);
- g_shaderFrontInit.setUniform(gl,"Alpha", g_opacity, 1);
+ // uses g_AlphaUni
+ g_shaderState.attachShaderProgram(gl, g_shaderFrontInit, true);
DrawModel(gl);
- g_shaderFrontInit.unbind(gl);
+ g_shaderState.useProgram(gl, false);
// ---------------------------------------------------------------------
// 2. Depth Peeling + Blending
@@ -681,11 +708,13 @@ public class DualDepthPeeling implements GLEventListener, KeyListener, MouseList
gl.glBeginQuery(GL2.GL_SAMPLES_PASSED, g_queryId[0]);
}
- g_shaderFrontPeel.bind(gl);
- g_shaderFrontPeel.bindTextureRECT(gl,"DepthTex", g_frontDepthTexId[prevId], 0);
- g_shaderFrontPeel.setUniform(gl,"Alpha", g_opacity, 1);
+ // uses g_DepthBlenderTexUnit
+ // uses g_FrontBlenderTexUnit
+ // uses g_AlphaUni
+ g_shaderState.attachShaderProgram(gl, g_shaderDualPeel, true);
+ GLHelper.bindTextureRECT(gl, g_frontDepthTexId[prevId], g_DepthBlenderTexUnit.intValue());
DrawModel(gl);
- g_shaderFrontPeel.unbind(gl);
+ g_shaderState.useProgram(gl, false);
if (g_useOQ) {
gl.glEndQuery(GL2.GL_SAMPLES_PASSED);
@@ -702,10 +731,11 @@ public class DualDepthPeeling implements GLEventListener, KeyListener, MouseList
gl.glBlendFuncSeparate(GL2.GL_DST_ALPHA, GL2.GL_ONE,
GL2.GL_ZERO, GL2.GL_ONE_MINUS_SRC_ALPHA);
- g_shaderFrontBlend.bind(gl);
- g_shaderFrontBlend.bindTextureRECT(gl,"TempTex", g_frontColorTexId[currId], 0);
+ // uses g_TempTexUnit
+ g_shaderState.attachShaderProgram(gl, g_shaderDualBlend, true);
+ GLHelper.bindTextureRECT(gl, g_frontColorTexId[currId], g_TempTexUnit.intValue());
gl.glCallList(g_quadDisplayList);
- g_shaderFrontBlend.unbind(gl);
+ g_shaderState.useProgram(gl, false);
gl.glDisable(GL2.GL_BLEND);
@@ -726,11 +756,11 @@ public class DualDepthPeeling implements GLEventListener, KeyListener, MouseList
gl.glDrawBuffer(GL2.GL_BACK);
gl.glDisable(GL2.GL_DEPTH_TEST);
- g_shaderFrontFinal.bind(gl);
- g_shaderFrontFinal.setUniform(gl,"BackgroundColor", g_backgroundColor, 3);
- g_shaderFrontFinal.bindTextureRECT(gl,"ColorTex", g_frontColorBlenderTexId[0], 0);
+ // uses g_backgroundColorUni
+ g_shaderState.attachShaderProgram(gl, g_shaderFrontFinal, true);
+ GLHelper.bindTextureRECT(gl, g_frontColorBlenderTexId[0], g_ColorTexUnit.intValue());
gl.glCallList(g_quadDisplayList);
- g_shaderFrontFinal.unbind(gl);
+ g_shaderState.useProgram(gl, false);
}
//--------------------------------------------------------------------------
@@ -752,10 +782,10 @@ public class DualDepthPeeling implements GLEventListener, KeyListener, MouseList
gl.glBlendFunc(GL2.GL_ONE, GL2.GL_ONE);
gl.glEnable(GL2.GL_BLEND);
- g_shaderAverageInit.bind(gl);
- g_shaderAverageInit.setUniform(gl,"Alpha", g_opacity, 1);
+ // uses g_AlphaUni
+ g_shaderState.attachShaderProgram(gl, g_shaderAverageInit, true);
DrawModel(gl);
- g_shaderAverageInit.unbind(gl);
+ g_shaderState.useProgram(gl, false);
gl.glDisable(GL2.GL_BLEND);
@@ -767,12 +797,12 @@ public class DualDepthPeeling implements GLEventListener, KeyListener, MouseList
gl.glBindFramebuffer(GL2.GL_FRAMEBUFFER, 0);
gl.glDrawBuffer(GL2.GL_BACK);
- g_shaderAverageFinal.bind(gl);
- g_shaderAverageFinal.setUniform(gl,"BackgroundColor", g_backgroundColor, 3);
- g_shaderAverageFinal.bindTextureRECT(gl,"ColorTex0", g_accumulationTexId[0], 0);
- g_shaderAverageFinal.bindTextureRECT(gl,"ColorTex1", g_accumulationTexId[1], 1);
+ // uses g_backgroundColorUni
+ g_shaderState.attachShaderProgram(gl, g_shaderAverageFinal, true);
+ GLHelper.bindTextureRECT(gl, g_accumulationTexId[0], g_ColorTex0Unit.intValue());
+ GLHelper.bindTextureRECT(gl, g_accumulationTexId[1], g_ColorTex1Unit.intValue());
gl.glCallList(g_quadDisplayList);
- g_shaderAverageFinal.unbind(gl);
+ g_shaderState.useProgram(gl, false);
}
//--------------------------------------------------------------------------
@@ -794,10 +824,9 @@ public class DualDepthPeeling implements GLEventListener, KeyListener, MouseList
gl.glBlendFunc(GL2.GL_ONE, GL2.GL_ONE);
gl.glEnable(GL2.GL_BLEND);
- g_shaderWeightedSumInit.bind(gl);
- g_shaderWeightedSumInit.setUniform(gl,"Alpha", g_opacity, 1);
+ g_shaderState.attachShaderProgram(gl, g_shaderWeightedSumInit, true);
DrawModel(gl);
- g_shaderWeightedSumInit.unbind(gl);
+ g_shaderState.useProgram(gl, false);
gl.glDisable(GL2.GL_BLEND);
@@ -808,11 +837,10 @@ public class DualDepthPeeling implements GLEventListener, KeyListener, MouseList
gl.glBindFramebuffer(GL2.GL_FRAMEBUFFER, 0);
gl.glDrawBuffer(GL2.GL_BACK);
- g_shaderWeightedSumFinal.bind(gl);
- g_shaderWeightedSumFinal.setUniform(gl,"BackgroundColor", g_backgroundColor, 3);
- g_shaderWeightedSumFinal.bindTextureRECT(gl,"ColorTex", g_accumulationTexId[0], 0);
+ g_shaderState.attachShaderProgram(gl, g_shaderWeightedSumFinal, true);
+ GLHelper.bindTextureRECT(gl, g_accumulationTexId[0], this.g_ColorTexUnit.intValue());
gl.glCallList(g_quadDisplayList);
- g_shaderWeightedSumFinal.unbind(gl);
+ g_shaderState.useProgram(gl, false);
}
@@ -885,12 +913,13 @@ public class DualDepthPeeling implements GLEventListener, KeyListener, MouseList
break;
case 'b':
g_backgroundColor = (g_backgroundColor == g_white) ? g_black : g_white;
+ g_backgroundColorUni.setData(g_backgroundColor);
break;
case 'o':
g_showOsd = !g_showOsd;
break;
case 'r':
- ReloadShaders(m_kGL);
+ reloadShaders = true;
break;
case '1':
g_mode = DUAL_PEELING_MODE;
@@ -905,43 +934,51 @@ public class DualDepthPeeling implements GLEventListener, KeyListener, MouseList
g_mode = WEIGHTED_SUM_MODE;
break;
case 'a':
- g_opacity[0] -= 0.05;
- g_opacity[0] = (float)Math.max(g_opacity[0], 0.0);
+ g_opacity -= 0.05;
+ g_opacity = (float)Math.max(g_opacity, 0.0);
+ g_AlphaUni.setData(g_opacity);
break;
case 'd':
- g_opacity[0] += 0.05;
- g_opacity[0] = (float)Math.min(g_opacity[0], 1.0);
+ g_opacity += 0.05;
+ g_opacity = (float)Math.min(g_opacity, 1.0);
+ g_AlphaUni.setData(g_opacity);
break;
}
}
@Override
- public void display(GLAutoDrawable arg0) {
- GLU glu = GLU.createGLU(m_kGL);
+ public void display(GLAutoDrawable arg0) {
+ GL2 gl = arg0.getGL().getGL2();
+
+ if(reloadShaders) {
+ reloadShaders = false;
+ ReloadShaders(gl);
+ }
+ GLU glu = GLU.createGLU(gl);
g_numGeoPasses = 0;
- m_kGL.glMatrixMode(GL2.GL_MODELVIEW);
- m_kGL.glLoadIdentity();
+ gl.glMatrixMode(GL2.GL_MODELVIEW);
+ gl.glLoadIdentity();
glu.gluLookAt(g_pos[0], g_pos[1], g_pos[2], g_pos[0], g_pos[1], 0, 0, 1, 0);
- m_kGL.glRotatef(g_rot[0], 1, 0, 0);
- m_kGL.glRotatef(g_rot[1], 0, 1, 0);
- m_kGL.glTranslatef(g_bbTrans[0], g_bbTrans[1], g_bbTrans[2]);
- m_kGL.glScalef(g_bbScale, g_bbScale, g_bbScale);
+ gl.glRotatef(g_rot[0], 1, 0, 0);
+ gl.glRotatef(g_rot[1], 0, 1, 0);
+ gl.glTranslatef(g_bbTrans[0], g_bbTrans[1], g_bbTrans[2]);
+ gl.glScalef(g_bbScale, g_bbScale, g_bbScale);
switch (g_mode) {
case DUAL_PEELING_MODE:
- RenderDualPeeling(m_kGL);
+ RenderDualPeeling(gl);
break;
case F2B_PEELING_MODE:
- RenderFrontToBackPeeling(m_kGL);
+ RenderFrontToBackPeeling(gl);
break;
case WEIGHTED_AVERAGE_MODE:
- RenderAverageColors(m_kGL);
+ RenderAverageColors(gl);
break;
case WEIGHTED_SUM_MODE:
- RenderWeightedSum(m_kGL);
+ RenderWeightedSum(gl);
break;
}
@@ -960,39 +997,35 @@ public class DualDepthPeeling implements GLEventListener, KeyListener, MouseList
@Override
public void init(GLAutoDrawable drawable) {
System.err.println( "init" );
- GL gl = drawable.setGL(new DebugGL2(drawable.getGL().getGL2()));
- m_kGL = gl.getGL2();
- //m_kGL = m_kCanvas.getGL().getGL2();
+ GL2 gl = drawable.getGL().getGL2();
m_kCanvas.setAutoSwapBufferMode( false );
-
-
// Allocate render targets first
try {
- InitDualPeelingRenderTargets(m_kGL);
+ InitDualPeelingRenderTargets(gl);
} catch ( GLException e )
{
try {
- InitDualPeelingRenderTargets(m_kGL);
+ InitDualPeelingRenderTargets(gl);
} catch ( GLException e1 )
{
System.err.println( e1.getStackTrace() );
}
}
- InitFrontPeelingRenderTargets(m_kGL);
- InitAccumulationRenderTargets(m_kGL);
- m_kGL.glBindFramebuffer(GL2.GL_FRAMEBUFFER, 0);
+ InitFrontPeelingRenderTargets(gl);
+ InitAccumulationRenderTargets(gl);
+ gl.glBindFramebuffer(GL2.GL_FRAMEBUFFER, 0);
- BuildShaders(m_kGL);
- LoadModel(m_kGL, MODEL_FILENAME);
- MakeFullScreenQuad(m_kGL);
+ BuildShaders(gl);
+ LoadModel(gl, MODEL_FILENAME);
+ MakeFullScreenQuad(gl);
- m_kGL.glDisable(GL2.GL_CULL_FACE);
- m_kGL.glDisable(GL2.GL_LIGHTING);
- m_kGL.glDisable(GL2.GL_NORMALIZE);
+ gl.glDisable(GL2.GL_CULL_FACE);
+ gl.glDisable(GL2.GL_LIGHTING);
+ gl.glDisable(GL2.GL_NORMALIZE);
- m_kGL.glGenQueries(1, g_queryId, 0);
+ gl.glGenQueries(1, g_queryId, 0);
}
@@ -1023,7 +1056,6 @@ public class DualDepthPeeling implements GLEventListener, KeyListener, MouseList
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glViewport(0, 0, g_imageWidth, g_imageHeight);
-
}
diff --git a/src/demos/dualDepthPeeling/GLHelper.java b/src/demos/dualDepthPeeling/GLHelper.java
new file mode 100644
index 0000000..cf1cccc
--- /dev/null
+++ b/src/demos/dualDepthPeeling/GLHelper.java
@@ -0,0 +1,53 @@
+package demos.dualDepthPeeling;
+
+
+// Translated from C++ Version see below:
+//
+// GLSLProgramObject.h - Wrapper for GLSL program objects
+//
+// Author: Louis Bavoil
+// Email: sdkfeedback@nvidia.com
+//
+// Copyright (c) NVIDIA Corporation. All rights reserved.
+////////////////////////////////////////////////////////////////////////////////
+import javax.media.opengl.GL2;
+
+public class GLHelper
+{
+ public static void setTextureUnit(GL2 gl, int progId, String texname, int texunit)
+ {
+ int[] params = new int[]{0};
+ gl.glGetProgramiv( progId, GL2.GL_LINK_STATUS, params, 0);
+ if ( params[0] != 1 ) {
+ System.err.println( "Error: setTextureUnit needs program to be linked.");
+ }
+ int id = gl.glGetUniformLocation(progId, texname );
+ if (id == -1) {
+ System.err.println( "Warning: Invalid texture " + texname );
+ return;
+ }
+ gl.glUniform1i(id, texunit);
+ }
+
+
+ public static void bindTexture(GL2 gl, int target, int texid, int texUnit)
+ {
+ gl.glActiveTexture(GL2.GL_TEXTURE0 + texUnit);
+ gl.glBindTexture(target, texid);
+ gl.glActiveTexture(GL2.GL_TEXTURE0);
+ }
+
+
+ public static void bindTexture2D(GL2 gl, int texid, int texUnit) {
+ bindTexture(gl, GL2.GL_TEXTURE_2D, texid, texUnit);
+ }
+
+ public static void bindTexture3D(GL2 gl, int texid, int texUnit) {
+ bindTexture(gl, GL2.GL_TEXTURE_3D, texid, texUnit);
+ }
+
+ // g_shaderDualPeel.bindTextureRECT(gl, g_shaderState, s_DepthBlenderTex, g_dualDepthTexId[prevId]);
+ public static void bindTextureRECT(GL2 gl, int texid, int texUnit) {
+ bindTexture(gl, GL2.GL_TEXTURE_RECTANGLE_ARB, texid, texUnit);
+ }
+};
diff --git a/src/demos/dualDepthPeeling/GLSLProgramObject.java b/src/demos/dualDepthPeeling/GLSLProgramObject.java
deleted file mode 100644
index 68d0e9a..0000000
--- a/src/demos/dualDepthPeeling/GLSLProgramObject.java
+++ /dev/null
@@ -1,283 +0,0 @@
-package demos.dualDepthPeeling;
-
-
-// Translated from C++ Version see below:
-//
-// GLSLProgramObject.h - Wrapper for GLSL program objects
-//
-// Author: Louis Bavoil
-// Email: sdkfeedback@nvidia.com
-//
-// Copyright (c) NVIDIA Corporation. All rights reserved.
-////////////////////////////////////////////////////////////////////////////////
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.Vector;
-
-import javax.media.opengl.GL2;
-
-import java.net.URL;
-
-public class GLSLProgramObject
-{
- public GLSLProgramObject()
- {
- _progId = 0;
- }
-
- public void destroy(GL2 gl)
- {
- for (int i = 0; i < _vertexShaders.size(); i++) {
- gl.glDeleteShader(_vertexShaders.elementAt(i));
- }
- for (int i = 0; i < _fragmentShaders.size(); i++) {
- gl.glDeleteShader(_fragmentShaders.elementAt(i));
- }
- if (_progId != 0) {
- gl.glDeleteProgram(_progId);
- }
- }
-
-
- public void bind(GL2 gl)
- {
- gl.glUseProgram(_progId);
- }
-
-
- public void unbind(GL2 gl)
- {
- gl.glUseProgram(0);
- }
-
-
- public void setUniform(GL2 gl, String name, float[] val, int count)
- {
- int id = gl.glGetUniformLocation(_progId, name );
- if (id == -1) {
- System.err.println( "Warning: Invalid uniform parameter " + name ) ;
- return;
- }
- switch (count) {
- case 1:
- gl.glUniform1fv(id, 1, val, 0);
- break;
- case 2:
- gl.glUniform2fv(id, 1, val, 0);
- break;
- case 3:
- gl.glUniform3fv(id, 1, val, 0);
- break;
- case 4:
- gl.glUniform4fv(id, 1, val, 0);
- break;
- }
- }
-
-
- public void setTextureUnit(GL2 gl, String texname, int texunit)
- {
- int[] params = new int[]{0};
- gl.glGetProgramiv( _progId, GL2.GL_LINK_STATUS, params, 0);
- if ( params[0] != 1 ) {
- System.err.println( "Error: setTextureUnit needs program to be linked.");
- }
- int id = gl.glGetUniformLocation(_progId, texname );
- if (id == -1) {
- System.err.println( "Warning: Invalid texture " + texname );
- return;
- }
- gl.glUniform1i(id, texunit);
- }
-
-
- public void bindTexture(GL2 gl, int target,String texname, int texid, int texunit)
- {
- gl.glActiveTexture(GL2.GL_TEXTURE0 + texunit);
- gl.glBindTexture(target, texid);
- setTextureUnit(gl, texname, texunit);
- gl.glActiveTexture(GL2.GL_TEXTURE0);
- }
-
-
- public void bindTexture2D(GL2 gl, String texname, int texid, int texunit) {
- bindTexture(gl, GL2.GL_TEXTURE_2D, texname, texid, texunit);
- }
-
- public void bindTexture3D(GL2 gl, String texname, int texid, int texunit) {
- bindTexture(gl, GL2.GL_TEXTURE_3D, texname, texid, texunit);
- }
-
- public void bindTextureRECT(GL2 gl, String texname, int texid, int texunit) {
- bindTexture(gl, GL2.GL_TEXTURE_RECTANGLE_ARB, texname, texid, texunit);
- }
-
- public void attachVertexShader(GL2 gl, String filename)
- {
- URL fileURL = getClass().getClassLoader().getResource(
- File.separator + "demos" +
- File.separator + "dualDepthPeeling" +
- File.separator + "shaders" + File.separator + filename);
- if ( fileURL != null )
- {
- String content = "";
- BufferedReader input = null;
- try {
-
- input = new BufferedReader(new InputStreamReader(fileURL.openStream()));
- String line = null;
-
- while ( (line = input.readLine()) != null) {
- content += line + "\n";
- }
- } catch (FileNotFoundException kFNF) {
- System.err.println("Unable to find the shader file " + filename);
- } catch (IOException kIO) {
- System.err.println("Problem reading the shader file " + filename);
- } finally {
- try {
- if (input != null) {
- input.close();
- }
- } catch (IOException closee) {}
- }
-
-
- int iID = gl.glCreateShader( GL2.GL_VERTEX_SHADER );
-
- String[] akProgramText = new String[1];
- // find and replace program name with "main"
- akProgramText[0] = content;
-
- int[] params = new int[]{0};
-
- int[] aiLength = new int[1];
- aiLength[0] = akProgramText[0].length();
- int iCount = 1;
- gl.glShaderSource( iID, iCount, akProgramText, aiLength, 0);
- gl.glCompileShader(iID);
- gl.glGetShaderiv( iID, GL2.GL_COMPILE_STATUS, params, 0);
- if ( params[0] != 1 )
- {
- System.err.println(filename);
- System.err.println("compile status: " + params[0]);
- gl.glGetShaderiv( iID, GL2.GL_INFO_LOG_LENGTH, params, 0);
- System.err.println("log length: " + params[0]);
- byte[] abInfoLog = new byte[params[0]];
- gl.glGetShaderInfoLog(iID, params[0], params, 0, abInfoLog, 0);
- System.err.println( new String(abInfoLog) );
- System.exit(-1);
- }
- _vertexShaders.add(iID);
- }
- else
- {
- System.err.println("Unable to find the shader file " + filename);
- }
- }
-
- public void attachFragmentShader(GL2 gl, String filename)
- {
- URL fileURL = getClass().getClassLoader().getResource(
- File.separator + "demos" +
- File.separator + "dualDepthPeeling" +
- File.separator + "shaders" + File.separator + filename);
- if ( fileURL != null )
- {
- String content = "";
- BufferedReader input = null;
- try {
-
- input = new BufferedReader(new InputStreamReader(fileURL.openStream()));
- String line = null;
-
- while ( (line = input.readLine()) != null) {
- content += line + "\n";
- }
- } catch (FileNotFoundException kFNF) {
- System.err.println("Unable to find the shader file " + filename);
- } catch (IOException kIO) {
- System.err.println("Problem reading the shader file " + filename);
- } finally {
- try {
- if (input != null) {
- input.close();
- }
- } catch (IOException closee) {}
- }
-
-
- int iID = gl.glCreateShader( GL2.GL_FRAGMENT_SHADER );
-
- String[] akProgramText = new String[1];
- // find and replace program name with "main"
- akProgramText[0] = content;
-
- int[] params = new int[]{0};
-
- int[] aiLength = new int[1];
- aiLength[0] = akProgramText[0].length();
- int iCount = 1;
- gl.glShaderSource( iID, iCount, akProgramText, aiLength, 0);
- gl.glCompileShader(iID);
- gl.glGetShaderiv( iID, GL2.GL_COMPILE_STATUS, params, 0);
- if ( params[0] != 1 )
- {
- System.err.println(filename);
- System.err.println("compile status: " + params[0]);
- gl.glGetShaderiv( iID, GL2.GL_INFO_LOG_LENGTH, params, 0);
- System.err.println("log length: " + params[0]);
- byte[] abInfoLog = new byte[params[0]];
- gl.glGetShaderInfoLog(iID, params[0], params, 0, abInfoLog, 0);
- System.err.println( new String(abInfoLog) );
- System.exit(-1);
- }
- _fragmentShaders.add(iID);
- }
- else
- {
- System.err.println("Unable to find the shader file " + filename);
- }
- }
-
-
- public void link(GL2 gl)
- {
- _progId = gl.glCreateProgram();
-
- for (int i = 0; i < _vertexShaders.size(); i++) {
- gl.glAttachShader(_progId, _vertexShaders.elementAt(i));
- }
-
- for (int i = 0; i < _fragmentShaders.size(); i++) {
- gl.glAttachShader(_progId, _fragmentShaders.elementAt(i));
- }
-
- gl.glLinkProgram(_progId);
-
- int[] params = new int[]{0};
- gl.glGetProgramiv( _progId, GL2.GL_LINK_STATUS, params, 0);
-
- if (params[0] != 1) {
-
- System.err.println("link status: " + params[0]);
- gl.glGetProgramiv( _progId, GL2.GL_INFO_LOG_LENGTH, params, 0);
- System.err.println("log length: " + params[0]);
-
- byte[] abInfoLog = new byte[params[0]];
- gl.glGetProgramInfoLog(_progId, params[0], params, 0, abInfoLog, 0);
- System.err.println( new String(abInfoLog) );
- }
- }
-
-
- public Integer getProgId() { return _progId; }
-
- protected Vector<Integer> _vertexShaders = new Vector<Integer>();
- protected Vector<Integer> _fragmentShaders = new Vector<Integer>();
- protected Integer _progId;
-};
diff --git a/src/demos/dualDepthPeeling/Model.java b/src/demos/dualDepthPeeling/Model.java
index 02f241c..3502879 100644
--- a/src/demos/dualDepthPeeling/Model.java
+++ b/src/demos/dualDepthPeeling/Model.java
@@ -27,6 +27,8 @@ import java.nio.IntBuffer;
import java.util.HashMap;
import java.util.Vector;
+import com.jogamp.common.util.IOUtil;
+
public class Model {
//
@@ -94,7 +96,7 @@ public class Model {
//
//////////////////////////////////////////////////////////////
public boolean loadModelFromFile( String file ) {
- URL fileURL = getClass().getClassLoader().getResource(File.separator + file);
+ URL fileURL = IOUtil.getResource(Model.class, file);
if ( fileURL != null )
{
BufferedReader input = null;