aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-09-02 07:11:18 +0200
committerSven Gothel <[email protected]>2014-09-02 07:11:18 +0200
commitdfae07ed4b0f164768c35b6e7ad008d81a3e68bb (patch)
tree7d3660f07e44540304977aee2316df7fec2566fa
parent70641322fc8e52417f934b452b573c9b39a734e9 (diff)
Bug 1043 - Add Tessellation Control and Evaluation Shader Support
- Add GL4.GL_TESS_CONTROL_SHADER and GL4.GL_TESS_EVALUATION_SHADER support for GLSL util class ShaderCode - Add unit test TestTessellationShader01GL4NEWT, testing TessellationShader01aGL4 and TessellationShader01bGL4
-rw-r--r--make/scripts/tests.sh5
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java72
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/TessellationShader01aGL4.java191
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/TessellationShader01bGL4.java142
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/newt/TestTessellationShader01GL4NEWT.java117
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/shader/tess_example01.fp6
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/shader/tess_example01.tcp12
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/shader/tess_example01.tep8
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/shader/tess_example01.vp12
9 files changed, 547 insertions, 18 deletions
diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh
index e0a16439d..a3a02070a 100644
--- a/make/scripts/tests.sh
+++ b/make/scripts/tests.sh
@@ -127,7 +127,7 @@ function jrun() {
#D_ARGS="-Djogl.debug.GLBufferStateTracker -Djogl.debug.GLBufferObjectTracker"
#D_ARGS="-Djogl.debug.GLBufferObjectTracker"
#D_ARGS="-Djogl.debug.GLBufferObjectTracker -Djogl.debug.GLArrayData -Djogl.debug.TraceGL -Djogl.debug.DebugGL"
- #D_ARGS="-Djogl.debug.GLSLCode"
+ D_ARGS="-Djogl.debug.GLSLCode"
#D_ARGS="-Djogl.debug.GLSLCode -Djogl.debug.TraceGL"
#D_ARGS="-Djogl.debug.GLSLCode -Djogl.debug.DebugGL"
#D_ARGS="-Djogl.debug.GLContext -Dnativewindow.debug.JAWT -Dnewt.debug.Window"
@@ -426,6 +426,7 @@ function testawtswt() {
#testnoawt com.jogamp.opengl.test.junit.jogl.demos.gl2.newt.TestGearsNEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.demos.gl2.newt.TestTeapotNEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.demos.gl3.newt.TestGeomShader01TextureGL3NEWT $*
+testnoawt com.jogamp.opengl.test.junit.jogl.demos.gl4.newt.TestTessellationShader01GL4NEWT $*
#
# av demos
@@ -533,7 +534,7 @@ function testawtswt() {
#testawt com.jogamp.opengl.test.junit.jogl.acore.TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT $*
#testawt com.jogamp.opengl.test.junit.jogl.acore.TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT $*
-testawt com.jogamp.opengl.test.junit.jogl.acore.TestGLOffscreenAutoDrawableBug1044AWT $*
+#testawt com.jogamp.opengl.test.junit.jogl.acore.TestGLOffscreenAutoDrawableBug1044AWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.ect.TestExclusiveContext01VSyncAnimNEWT $*
#testawt com.jogamp.opengl.test.junit.jogl.acore.ect.TestExclusiveContext01VSyncAnimAWT $*
diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java
index 574fc4205..f9f3b845f 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java
@@ -46,6 +46,7 @@ import java.util.Set;
import javax.media.opengl.GL;
import javax.media.opengl.GL2ES2;
import javax.media.opengl.GL3;
+import javax.media.opengl.GL4;
import javax.media.opengl.GLES2;
import javax.media.opengl.GLContext;
import javax.media.opengl.GLException;
@@ -67,29 +68,42 @@ import com.jogamp.common.util.VersionNumber;
public class ShaderCode {
public static final boolean DEBUG_CODE = Debug.isPropertyDefined("jogl.debug.GLSLCode", true);
- /** Unique resource suffix for {@link GL2ES2#GL_VERTEX_SHADER} in source code: <code>vp</code> */
+ /** Unique resource suffix for {@link GL2ES2#GL_VERTEX_SHADER} in source code: <code>{@value}</code> */
public static final String SUFFIX_VERTEX_SOURCE = "vp" ;
- /** Unique resource suffix for {@link GL2ES2#GL_VERTEX_SHADER} in binary: <code>bvp</code> */
+ /** Unique resource suffix for {@link GL2ES2#GL_VERTEX_SHADER} in binary: <code>{@value}</code> */
public static final String SUFFIX_VERTEX_BINARY = "bvp" ;
- /** Unique resource suffix for {@link GL3#GL_GEOMETRY_SHADER} in source code: <code>gp</code> */
+ /** Unique resource suffix for {@link GL3#GL_GEOMETRY_SHADER} in source code: <code>{@value}</code> */
public static final String SUFFIX_GEOMETRY_SOURCE = "gp" ;
- /** Unique resource suffix for {@link GL3#GL_GEOMETRY_SHADER} in binary: <code>bgp</code> */
+ /** Unique resource suffix for {@link GL3#GL_GEOMETRY_SHADER} in binary: <code>{@value}</code> */
public static final String SUFFIX_GEOMETRY_BINARY = "bgp" ;
- /** Unique resource suffix for {@link GL2ES2#GL_FRAGMENT_SHADER} in source code: <code>fp</code> */
+ /** Unique resource suffix for {@link GL4#GL_TESS_CONTROL_SHADER} in source code: <code>{@value}</code> */
+ public static final String SUFFIX_TESS_CONTROL_SOURCE = "tcp" ;
+
+ /** Unique resource suffix for {@link GL4#GL_TESS_CONTROL_SHADER} in binary: <code>{@value}</code> */
+ public static final String SUFFIX_TESS_CONTROL_BINARY = "btcp" ;
+
+ /** Unique resource suffix for {@link GL4#GL_TESS_EVALUATION_SHADER} in source code: <code>{@value}</code> */
+ public static final String SUFFIX_TESS_EVALUATION_SOURCE = "tep" ;
+
+ /** Unique resource suffix for {@link GL4#GL_TESS_EVALUATION_SHADER} in binary: <code>{@value}</code> */
+ public static final String SUFFIX_TESS_EVALUATION_BINARY = "btep" ;
+
+ /** Unique resource suffix for {@link GL2ES2#GL_FRAGMENT_SHADER} in source code: <code>{@value}</code> */
public static final String SUFFIX_FRAGMENT_SOURCE = "fp" ;
- /** Unique resource suffix for {@link GL2ES2#GL_FRAGMENT_SHADER} in binary: <code>bfp</code> */
+ /** Unique resource suffix for {@link GL2ES2#GL_FRAGMENT_SHADER} in binary: <code>{@value}</code> */
public static final String SUFFIX_FRAGMENT_BINARY = "bfp" ;
- /** Unique relative path for binary shader resources for {@link GLES2#GL_NVIDIA_PLATFORM_BINARY_NV NVIDIA}: <code>nvidia</code> */
+ /** Unique relative path for binary shader resources for {@link GLES2#GL_NVIDIA_PLATFORM_BINARY_NV NVIDIA}: <code>{@value}</code> */
public static final String SUB_PATH_NVIDIA = "nvidia" ;
/**
- * @param type either {@link GL2ES2#GL_VERTEX_SHADER}, {@link GL2ES2#GL_FRAGMENT_SHADER} or {@link GL3#GL_GEOMETRY_SHADER}
+ * @param type either {@link GL2ES2#GL_VERTEX_SHADER}, {@link GL2ES2#GL_FRAGMENT_SHADER}, {@link GL3#GL_GEOMETRY_SHADER},
+ * {@link GL4#GL_TESS_CONTROL_SHADER} or {@link GL4#GL_TESS_EVALUATION_SHADER}.
* @param count number of shaders
* @param source CharSequence array containing the shader sources, organized as <code>source[count][strings-per-shader]</code>.
* May be either an immutable <code>String</code> - or mutable <code>StringBuilder</code> array.
@@ -104,6 +118,8 @@ public class ShaderCode {
case GL2ES2.GL_VERTEX_SHADER:
case GL2ES2.GL_FRAGMENT_SHADER:
case GL3.GL_GEOMETRY_SHADER:
+ case GL4.GL_TESS_CONTROL_SHADER:
+ case GL4.GL_TESS_EVALUATION_SHADER:
break;
default:
throw new GLException("Unknown shader type: "+type);
@@ -122,7 +138,8 @@ public class ShaderCode {
}
/**
- * @param type either {@link GL2ES2#GL_VERTEX_SHADER}, {@link GL2ES2#GL_FRAGMENT_SHADER} or {@link GL3#GL_GEOMETRY_SHADER}
+ * @param type either {@link GL2ES2#GL_VERTEX_SHADER}, {@link GL2ES2#GL_FRAGMENT_SHADER}, {@link GL3#GL_GEOMETRY_SHADER},
+ * {@link GL4#GL_TESS_CONTROL_SHADER} or {@link GL4#GL_TESS_EVALUATION_SHADER}.
* @param count number of shaders
* @param binary binary buffer containing the shader binaries,
*/
@@ -131,6 +148,8 @@ public class ShaderCode {
case GL2ES2.GL_VERTEX_SHADER:
case GL2ES2.GL_FRAGMENT_SHADER:
case GL3.GL_GEOMETRY_SHADER:
+ case GL4.GL_TESS_CONTROL_SHADER:
+ case GL4.GL_TESS_EVALUATION_SHADER:
break;
default:
throw new GLException("Unknown shader type: "+type);
@@ -148,7 +167,8 @@ public class ShaderCode {
* which location is resolved using the <code>context</code> class, see {@link #readShaderSource(Class, String)}.
*
* @param gl current GL object to determine whether a shader compiler is available. If null, no validation is performed.
- * @param type either {@link GL2ES2#GL_VERTEX_SHADER}, {@link GL2ES2#GL_FRAGMENT_SHADER} or {@link GL3#GL_GEOMETRY_SHADER}
+ * @param type either {@link GL2ES2#GL_VERTEX_SHADER}, {@link GL2ES2#GL_FRAGMENT_SHADER}, {@link GL3#GL_GEOMETRY_SHADER},
+ * {@link GL4#GL_TESS_CONTROL_SHADER} or {@link GL4#GL_TESS_EVALUATION_SHADER}.
* @param count number of shaders
* @param context class used to help resolving the source location
* @param sourceFiles array of source locations, organized as <code>sourceFiles[count]</code>
@@ -192,7 +212,8 @@ public class ShaderCode {
* Creates a complete {@link ShaderCode} object while reading the shader binary of <code>binaryFile</code>,
* which location is resolved using the <code>context</code> class, see {@link #readShaderBinary(Class, String)}.
*
- * @param type either {@link GL2ES2#GL_VERTEX_SHADER}, {@link GL2ES2#GL_FRAGMENT_SHADER} or {@link GL3#GL_GEOMETRY_SHADER}
+ * @param type either {@link GL2ES2#GL_VERTEX_SHADER}, {@link GL2ES2#GL_FRAGMENT_SHADER}, {@link GL3#GL_GEOMETRY_SHADER},
+ * {@link GL4#GL_TESS_CONTROL_SHADER} or {@link GL4#GL_TESS_EVALUATION_SHADER}.
* @param count number of shaders
* @param context class used to help resolving the source location
* @param binFormat a valid native binary format as they can be queried by {@link ShaderUtil#getShaderBinaryFormats(GL)}.
@@ -225,14 +246,21 @@ public class ShaderCode {
* <li>Source<ul>
* <li>{@link GL2ES2#GL_VERTEX_SHADER vertex}: {@link #SUFFIX_VERTEX_SOURCE}</li>
* <li>{@link GL2ES2#GL_FRAGMENT_SHADER fragment}: {@link #SUFFIX_FRAGMENT_SOURCE}</li>
- * <li>{@link GL3#GL_GEOMETRY_SHADER geometry}: {@link #SUFFIX_GEOMETRY_SOURCE}</li></ul></li>
+ * <li>{@link GL3#GL_GEOMETRY_SHADER geometry}: {@link #SUFFIX_GEOMETRY_SOURCE}</li>
+ * <li>{@link GL4#GL_TESS_CONTROL_SHADER tess-ctrl}: {@link #SUFFIX_TESS_CONTROL_SOURCE}</li>
+ * <li>{@link GL4#GL_TESS_EVALUATION_SHADER tess-eval}: {@link #SUFFIX_TESS_EVALUATION_SOURCE}</li>
+ * </ul></li>
* <li>Binary<ul>
* <li>{@link GL2ES2#GL_VERTEX_SHADER vertex}: {@link #SUFFIX_VERTEX_BINARY}</li>
* <li>{@link GL2ES2#GL_FRAGMENT_SHADER fragment}: {@link #SUFFIX_FRAGMENT_BINARY}</li>
- * <li>{@link GL3#GL_GEOMETRY_SHADER geometry}: {@link #SUFFIX_GEOMETRY_BINARY}</li></ul></li>
+ * <li>{@link GL3#GL_GEOMETRY_SHADER geometry}: {@link #SUFFIX_GEOMETRY_BINARY}</li>
+ * <li>{@link GL4#GL_TESS_CONTROL_SHADER tess-ctrl}: {@link #SUFFIX_TESS_CONTROL_BINARY}</li>
+ * <li>{@link GL4#GL_TESS_EVALUATION_SHADER tess-eval}: {@link #SUFFIX_TESS_EVALUATION_BINARY}</li>
+ * </ul></li>
* </ul>
* @param binary true for a binary resource, false for a source resource
- * @param type either {@link GL2ES2#GL_VERTEX_SHADER}, {@link GL2ES2#GL_FRAGMENT_SHADER} or {@link GL3#GL_GEOMETRY_SHADER}
+ * @param type either {@link GL2ES2#GL_VERTEX_SHADER}, {@link GL2ES2#GL_FRAGMENT_SHADER}, {@link GL3#GL_GEOMETRY_SHADER},
+ * {@link GL4#GL_TESS_CONTROL_SHADER} or {@link GL4#GL_TESS_EVALUATION_SHADER}.
*
* @throws GLException if <code>type</code> is not supported
*
@@ -246,6 +274,10 @@ public class ShaderCode {
return binary?SUFFIX_FRAGMENT_BINARY:SUFFIX_FRAGMENT_SOURCE;
case GL3.GL_GEOMETRY_SHADER:
return binary?SUFFIX_GEOMETRY_BINARY:SUFFIX_GEOMETRY_SOURCE;
+ case GL4.GL_TESS_CONTROL_SHADER:
+ return binary?SUFFIX_TESS_CONTROL_BINARY:SUFFIX_TESS_CONTROL_SOURCE;
+ case GL4.GL_TESS_EVALUATION_SHADER:
+ return binary?SUFFIX_TESS_EVALUATION_BINARY:SUFFIX_TESS_EVALUATION_SOURCE;
default:
throw new GLException("illegal shader type: "+type);
}
@@ -324,7 +356,8 @@ public class ShaderCode {
*
* @param gl current GL object to determine whether a shader compiler is available (if <code>source</code> is used),
* or to determine the shader binary format (if <code>binary</code> is used).
- * @param type either {@link GL2ES2#GL_VERTEX_SHADER}, {@link GL2ES2#GL_FRAGMENT_SHADER} or {@link GL3#GL_GEOMETRY_SHADER}
+ * @param type either {@link GL2ES2#GL_VERTEX_SHADER}, {@link GL2ES2#GL_FRAGMENT_SHADER}, {@link GL3#GL_GEOMETRY_SHADER},
+ * {@link GL4#GL_TESS_CONTROL_SHADER} or {@link GL4#GL_TESS_EVALUATION_SHADER}.
* @param count number of shaders
* @param context class used to help resolving the source and binary location
* @param srcRoot relative <i>root</i> path for <code>srcBasenames</code> optional
@@ -430,7 +463,8 @@ public class ShaderCode {
*
* @param gl current GL object to determine whether a shader compiler is available (if <code>source</code> is used),
* or to determine the shader binary format (if <code>binary</code> is used).
- * @param type either {@link GL2ES2#GL_VERTEX_SHADER}, {@link GL2ES2#GL_FRAGMENT_SHADER} or {@link GL3#GL_GEOMETRY_SHADER}
+ * @param type either {@link GL2ES2#GL_VERTEX_SHADER}, {@link GL2ES2#GL_FRAGMENT_SHADER}, {@link GL3#GL_GEOMETRY_SHADER},
+ * {@link GL4#GL_TESS_CONTROL_SHADER} or {@link GL4#GL_TESS_EVALUATION_SHADER}.
* @param context class used to help resolving the source and binary location
* @param srcRoot relative <i>root</i> path for <code>basename</code> optional
* @param binRoot relative <i>root</i> path for <code>basename</code>
@@ -468,6 +502,10 @@ public class ShaderCode {
return "FRAGMENT_SHADER";
case GL3.GL_GEOMETRY_SHADER:
return "GEOMETRY_SHADER";
+ case GL4.GL_TESS_CONTROL_SHADER:
+ return "TESS_CONTROL_SHADER";
+ case GL4.GL_TESS_EVALUATION_SHADER:
+ return "TESS_EVALUATION_SHADER";
}
return "UNKNOWN_SHADER";
}
@@ -960,6 +998,8 @@ public class ShaderCode {
switch ( shaderType ) {
case GL2ES2.GL_VERTEX_SHADER:
case GL3.GL_GEOMETRY_SHADER:
+ case GL4.GL_TESS_CONTROL_SHADER:
+ case GL4.GL_TESS_EVALUATION_SHADER:
defaultPrecision = gl3_default_precision_vp_gp; break;
case GL2ES2.GL_FRAGMENT_SHADER:
defaultPrecision = gl3_default_precision_fp; break;
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/TessellationShader01aGL4.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/TessellationShader01aGL4.java
new file mode 100644
index 000000000..a5807a096
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/TessellationShader01aGL4.java
@@ -0,0 +1,191 @@
+/**
+ * Copyright 2014 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package com.jogamp.opengl.test.junit.jogl.demos.gl4;
+
+import java.nio.FloatBuffer;
+
+import javax.media.opengl.GL;
+import javax.media.opengl.GL2ES2;
+import javax.media.opengl.GL2ES3;
+import javax.media.opengl.GL2GL3;
+import javax.media.opengl.GL4;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLEventListener;
+
+import com.jogamp.opengl.util.glsl.ShaderCode;
+import com.jogamp.opengl.util.glsl.ShaderProgram;
+
+/**
+ * JOGL Tessellation ShaderCode GL4 test case.
+ * <p>
+ * Demonstrates tessellation-control and -evaluation shaders.
+ * </p>
+ *
+ * @author Raymond L. Rivera, 2014
+ * @author Sven Gothel
+ */
+public class TessellationShader01aGL4 implements GLEventListener {
+ private static final double ANIMATION_RATE = 950.0;
+
+ private ShaderProgram program;
+ private final int[] vertexArray = new int[1];
+ private FloatBuffer vertexOffset;
+ private FloatBuffer backgroundColor;
+
+
+ @Override
+ public void init(final GLAutoDrawable auto) {
+ final double theta = System.currentTimeMillis() / ANIMATION_RATE;
+ vertexOffset = FloatBuffer.allocate(4);
+ vertexOffset.put(0, (float)(Math.sin(theta) * 0.5f));
+ vertexOffset.put(1, (float)(Math.cos(theta) * 0.6f));
+ vertexOffset.put(2, 0.0f);
+ vertexOffset.put(3, 0.0f);
+
+ backgroundColor = FloatBuffer.allocate(4);
+ backgroundColor.put(0, 0.25f);
+ backgroundColor.put(1, 0.25f);
+ backgroundColor.put(2, 0.25f);
+ backgroundColor.put(3, 1.0f);
+
+ final GL4 gl = auto.getGL().getGL4();
+ program = createProgram(auto);
+ gl.glGenVertexArrays(vertexArray.length, vertexArray, 0);
+ gl.glBindVertexArray(vertexArray[0]);
+ gl.glPatchParameteri(GL4.GL_PATCH_VERTICES, 3);
+ gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_LINE);
+ }
+
+ @Override
+ public void display(final GLAutoDrawable auto) {
+ final GL4 gl = auto.getGL().getGL4();
+ final double value = System.currentTimeMillis() / ANIMATION_RATE;
+ gl.glClearBufferfv(GL2ES3.GL_COLOR, 0, backgroundColor);
+ gl.glUseProgram(program.program());
+ vertexOffset.put(0, (float)(Math.sin(value) * 0.5f));
+ vertexOffset.put(1, (float)(Math.cos(value) * 0.6f));
+ gl.glVertexAttrib4fv(0, vertexOffset);
+ gl.glDrawArrays(GL4.GL_PATCHES, 0, 3);
+ }
+
+ @Override
+ public void dispose(final GLAutoDrawable auto) {
+ final GL4 gl = auto.getGL().getGL4();
+ gl.glDeleteVertexArrays(vertexArray.length, vertexArray, 0);
+ program.destroy(gl);
+ }
+
+ @Override
+ public void reshape(final GLAutoDrawable auto, final int x, final int y, final int width, final int height) {
+ // final GL4 gl = auto.getGL().getGL4();
+ }
+
+ private ShaderProgram createProgram(final GLAutoDrawable auto) {
+ final GL4 gl = auto.getGL().getGL4();
+ final String vertexSource =
+ "#version 440 core \n" +
+ " \n" +
+ "layout (location = 0) in vec4 offset; \n" +
+ " \n" +
+ "void main(void) \n" +
+ "{ \n" +
+ " const vec4 vertices[3] = vec4[3] ( \n" +
+ " vec4( 0.25, 0.25, 0.5, 1.0), \n" +
+ " vec4(-0.25, -0.25, 0.5, 1.0), \n" +
+ " vec4( 0.25, -0.25, 0.5, 1.0)); \n" +
+ " gl_Position = vertices[gl_VertexID] + offset; \n" +
+ "} \n";
+ final String tessCtrlSource =
+ "#version 440 core \n" +
+ "layout (vertices = 3) out; \n" +
+ " \n" +
+ "void main(void) \n" +
+ "{ \n" +
+ " if (gl_InvocationID == 0) \n" +
+ " { \n" +
+ " gl_TessLevelInner[0] = 5.0; \n" +
+ " gl_TessLevelOuter[0] = 5.0; \n" +
+ " gl_TessLevelOuter[1] = 5.0; \n" +
+ " gl_TessLevelOuter[2] = 5.0; \n" +
+ " } \n" +
+ " gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;\n" +
+ "} \n";
+ final String tessEvalSource =
+ "#version 440 core \n" +
+ " \n" +
+ "layout (triangles, equal_spacing, cw) in; \n" +
+ " \n" +
+ "void main(void) \n" +
+ "{ \n" +
+ " gl_Position = (gl_TessCoord.x * gl_in[0].gl_Position) + \n" +
+ " (gl_TessCoord.y * gl_in[1].gl_Position) + \n" +
+ " (gl_TessCoord.z * gl_in[2].gl_Position); \n" +
+ "} \n";
+ final String fragmentSource =
+ "#version 440 core \n" +
+ " \n" +
+ "out vec4 color; \n" +
+ " \n" +
+ "void main(void) \n" +
+ "{ \n" +
+ " color = vec4(1.0, 1.0, 1.0, 1.0); \n" +
+ "} \n";
+
+ final ShaderCode vertexShader = createShader(gl, GL2ES2.GL_VERTEX_SHADER, vertexSource);
+ final ShaderCode tessCtrlShader = createShader(gl, GL4.GL_TESS_CONTROL_SHADER, tessCtrlSource);
+ final ShaderCode tessEvalShader = createShader(gl, GL4.GL_TESS_EVALUATION_SHADER, tessEvalSource);
+ final ShaderCode fragmentShader = createShader(gl, GL2ES2.GL_FRAGMENT_SHADER, fragmentSource);
+
+ final ShaderProgram program = new ShaderProgram();
+
+ program.init(gl);
+ program.add(vertexShader);
+ program.add(tessCtrlShader);
+ program.add(tessEvalShader);
+ program.add(fragmentShader);
+
+ program.link(gl, System.err);
+ if(!program.validateProgram(gl, System.out))
+ System.err.println("[error] Program linking failed.");
+
+ return program;
+ }
+
+ private ShaderCode createShader(final GL4 gl, final int shaderType, final String source) {
+ final String[][] sources = new String[1][1];
+ sources[0] = new String[]{ source };
+ final ShaderCode shader = new ShaderCode(shaderType, sources.length, sources);
+
+ final boolean compiled = shader.compile(gl, System.err);
+ if (!compiled)
+ System.err.println("[error] Shader compilation failed.");
+
+ return shader;
+ }
+
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/TessellationShader01bGL4.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/TessellationShader01bGL4.java
new file mode 100644
index 000000000..7be26e400
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/TessellationShader01bGL4.java
@@ -0,0 +1,142 @@
+/**
+ * Copyright 2014 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package com.jogamp.opengl.test.junit.jogl.demos.gl4;
+
+import java.nio.FloatBuffer;
+
+import javax.media.opengl.GL;
+import javax.media.opengl.GL2ES2;
+import javax.media.opengl.GL2ES3;
+import javax.media.opengl.GL2GL3;
+import javax.media.opengl.GL4;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLEventListener;
+import javax.media.opengl.GLException;
+
+import com.jogamp.opengl.util.glsl.ShaderCode;
+import com.jogamp.opengl.util.glsl.ShaderProgram;
+
+/**
+ * JOGL Tessellation ShaderCode GL4 test case.
+ * <p>
+ * Demonstrates tessellation-control and -evaluation shaders.
+ * </p>
+ *
+ * @author Raymond L. Rivera, 2014
+ * @author Sven Gothel
+ */
+public class TessellationShader01bGL4 implements GLEventListener {
+ private static final double ANIMATION_RATE = 950.0;
+
+ private ShaderProgram program;
+ private final int[] vertexArray = new int[1];
+ private FloatBuffer vertexOffset;
+ private FloatBuffer backgroundColor;
+
+
+ @Override
+ public void init(final GLAutoDrawable auto) {
+ final double theta = System.currentTimeMillis() / ANIMATION_RATE;
+ vertexOffset = FloatBuffer.allocate(4);
+ vertexOffset.put(0, (float)(Math.sin(theta) * 0.5f));
+ vertexOffset.put(1, (float)(Math.cos(theta) * 0.6f));
+ vertexOffset.put(2, 0.0f);
+ vertexOffset.put(3, 0.0f);
+
+ backgroundColor = FloatBuffer.allocate(4);
+ backgroundColor.put(0, 0.25f);
+ backgroundColor.put(1, 0.25f);
+ backgroundColor.put(2, 0.25f);
+ backgroundColor.put(3, 1.0f);
+
+ final GL4 gl = auto.getGL().getGL4();
+ program = createProgram(auto);
+ gl.glGenVertexArrays(vertexArray.length, vertexArray, 0);
+ gl.glBindVertexArray(vertexArray[0]);
+ gl.glPatchParameteri(GL4.GL_PATCH_VERTICES, 3);
+ gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_LINE);
+ }
+
+ @Override
+ public void display(final GLAutoDrawable auto) {
+ final GL4 gl = auto.getGL().getGL4();
+ final double value = System.currentTimeMillis() / ANIMATION_RATE;
+ gl.glClearBufferfv(GL2ES3.GL_COLOR, 0, backgroundColor);
+ gl.glUseProgram(program.program());
+ vertexOffset.put(0, (float)(Math.sin(value) * 0.5f));
+ vertexOffset.put(1, (float)(Math.cos(value) * 0.6f));
+ gl.glVertexAttrib4fv(0, vertexOffset);
+ gl.glDrawArrays(GL4.GL_PATCHES, 0, 3);
+ }
+
+ @Override
+ public void dispose(final GLAutoDrawable auto) {
+ final GL4 gl = auto.getGL().getGL4();
+ gl.glDeleteVertexArrays(vertexArray.length, vertexArray, 0);
+ program.destroy(gl);
+ }
+
+ @Override
+ public void reshape(final GLAutoDrawable auto, final int x, final int y, final int width, final int height) {
+ // final GL4 gl = auto.getGL().getGL4();
+ }
+
+ static final String shaderBasename = "tess_example01";
+
+ private ShaderProgram createProgram(final GLAutoDrawable auto) {
+ final GL4 gl = auto.getGL().getGL4();
+
+ final ShaderProgram sp;
+ {
+ final ShaderCode vs, tcs, tes, fs;
+ vs = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, this.getClass(),
+ "shader", "shader/bin", shaderBasename, true);
+ tcs = ShaderCode.create(gl, GL4.GL_TESS_CONTROL_SHADER, this.getClass(),
+ "shader", "shader/bin", shaderBasename, true);
+ tes = ShaderCode.create(gl, GL4.GL_TESS_EVALUATION_SHADER, this.getClass(),
+ "shader", "shader/bin", shaderBasename, true);
+ fs = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, this.getClass(),
+ "shader", "shader/bin", shaderBasename, true);
+ vs.defaultShaderCustomization(gl, true, true);
+ tcs.defaultShaderCustomization(gl, true, true);
+ tes.defaultShaderCustomization(gl, true, true);
+ fs.defaultShaderCustomization(gl, true, true);
+
+ sp = new ShaderProgram();
+ sp.add(gl, vs, System.err);
+ sp.add(gl, tcs, System.err);
+ sp.add(gl, tes, System.err);
+ sp.add(gl, fs, System.err);
+ if(!sp.link(gl, System.err)) {
+ throw new GLException("Couldn't link program: "+sp);
+ }
+ }
+
+ return sp;
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/newt/TestTessellationShader01GL4NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/newt/TestTessellationShader01GL4NEWT.java
new file mode 100644
index 000000000..a05dcec06
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/newt/TestTessellationShader01GL4NEWT.java
@@ -0,0 +1,117 @@
+/**
+ * Copyright 2014 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package com.jogamp.opengl.test.junit.jogl.demos.gl4.newt;
+
+import java.io.IOException;
+
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLEventListener;
+import javax.media.opengl.GLProfile;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.FixMethodOrder;
+import org.junit.runners.MethodSorters;
+
+import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.opengl.test.junit.jogl.demos.gl4.TessellationShader01aGL4;
+import com.jogamp.opengl.test.junit.jogl.demos.gl4.TessellationShader01bGL4;
+import com.jogamp.opengl.test.junit.util.MiscUtils;
+import com.jogamp.opengl.test.junit.util.QuitAdapter;
+import com.jogamp.opengl.test.junit.util.UITestCase;
+import com.jogamp.opengl.util.Animator;
+
+/**
+ * Test Geometry shader demo TessellationShader01aGL4 and TessellationShader01bGL4
+ */
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestTessellationShader01GL4NEWT extends UITestCase {
+ static long duration = 500; // ms
+
+ static GLCapabilities getCaps(final String profile) {
+ if( !GLProfile.isAvailable(profile) ) {
+ System.err.println("Profile "+profile+" n/a");
+ return null;
+ }
+ return new GLCapabilities(GLProfile.get(profile));
+ }
+
+ @Test
+ public void test01_01a() throws InterruptedException {
+ final GLCapabilities caps = getCaps(GLProfile.GL4);
+ if( null == caps ) { return; }
+ testImpl(caps, new TessellationShader01aGL4());
+ }
+
+ @Test
+ public void test02_01b() throws InterruptedException {
+ final GLCapabilities caps = getCaps(GLProfile.GL4);
+ if( null == caps ) { return; }
+ testImpl(caps, new TessellationShader01bGL4());
+ }
+
+ private void testImpl(final GLCapabilities caps, final GLEventListener glel) throws InterruptedException {
+ final GLWindow glWindow = GLWindow.create(caps);
+ Assert.assertNotNull(glWindow);
+ glWindow.setSize(800, 600);
+ glWindow.setVisible(true);
+ glWindow.setTitle("JOGL Tessellation Shader Test");
+ Assert.assertTrue(glWindow.isNativeValid());
+
+ final QuitAdapter quitAdapter = new QuitAdapter();
+ glWindow.addKeyListener(quitAdapter);
+ glWindow.addWindowListener(quitAdapter);
+ glWindow.addGLEventListener( glel );
+
+ final SnapshotGLEventListener snapshotGLEventListener = new SnapshotGLEventListener();
+ glWindow.addGLEventListener(snapshotGLEventListener);
+
+ final Animator animator = new Animator(glWindow);
+ animator.start();
+
+ animator.setUpdateFPSFrames(60, System.err);
+ snapshotGLEventListener.setMakeSnapshot();
+
+ while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration()<duration) {
+ Thread.sleep(100);
+ }
+
+ animator.stop();
+ glWindow.destroy();
+ }
+
+ public static void main(final String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ i++;
+ duration = MiscUtils.atol(args[i], duration);
+ }
+ }
+ org.junit.runner.JUnitCore.main(TestTessellationShader01GL4NEWT.class.getName());
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/shader/tess_example01.fp b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/shader/tess_example01.fp
new file mode 100644
index 000000000..8a3b23203
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/shader/tess_example01.fp
@@ -0,0 +1,6 @@
+
+out vec4 color;
+
+void main(void) {
+ color = vec4(1.0, 1.0, 1.0, 1.0);
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/shader/tess_example01.tcp b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/shader/tess_example01.tcp
new file mode 100644
index 000000000..b76aa580d
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/shader/tess_example01.tcp
@@ -0,0 +1,12 @@
+
+layout (vertices = 3) out;
+
+void main(void) {
+ if (gl_InvocationID == 0) {
+ gl_TessLevelInner[0] = 5.0;
+ gl_TessLevelOuter[0] = 5.0;
+ gl_TessLevelOuter[1] = 5.0;
+ gl_TessLevelOuter[2] = 5.0;
+ }
+ gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/shader/tess_example01.tep b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/shader/tess_example01.tep
new file mode 100644
index 000000000..9c307f5d4
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/shader/tess_example01.tep
@@ -0,0 +1,8 @@
+
+layout (triangles, equal_spacing, cw) in;
+
+void main(void) {
+ gl_Position = (gl_TessCoord.x * gl_in[0].gl_Position) +
+ (gl_TessCoord.y * gl_in[1].gl_Position) +
+ (gl_TessCoord.z * gl_in[2].gl_Position);
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/shader/tess_example01.vp b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/shader/tess_example01.vp
new file mode 100644
index 000000000..c207c1335
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/shader/tess_example01.vp
@@ -0,0 +1,12 @@
+
+layout (location = 0) in vec4 offset;
+
+void main(void)
+{
+ const vec4 vertices[3] =
+ vec4[3] (
+ vec4( 0.25, 0.25, 0.5, 1.0),
+ vec4(-0.25, -0.25, 0.5, 1.0),
+ vec4( 0.25, -0.25, 0.5, 1.0) );
+ gl_Position = vertices[gl_VertexID] + offset;
+}