aboutsummaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2012-10-26 09:24:40 +0200
committerSven Gothel <[email protected]>2012-10-26 09:24:40 +0200
commit4f05d5add18048c2fbd1837c0563446c11177e8c (patch)
tree8b7d919e59a60554c95ab56e9427d700d42df531 /src/test
parent0f198907181396c5aab545f621098ed2f210003a (diff)
ShaderCode: Add defaultShaderCustomization(..) to prelude shader source w/ GLSL version and default precision (if GLES) - Used by GearsES2/RedSquare/PointDemo (Made GLSL version proof)
Diffstat (limited to 'src/test')
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/GearsObjectES1.java7
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java8
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsObjectES2.java7
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/PointsDemoES2.java17
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquareES2.java6
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java13
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/PointsShader.fp17
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/PointsShader.vp5
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/RedSquareShader.fp17
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/RedSquareShader.vp15
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/RedSquareShader2.fp20
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/gears.fp10
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/gears.vp7
13 files changed, 69 insertions, 80 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/GearsObjectES1.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/GearsObjectES1.java
index 1208dad61..8276c6bb9 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/GearsObjectES1.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/GearsObjectES1.java
@@ -47,10 +47,9 @@ public class GearsObjectES1 extends GearsObject {
}
@Override
- public void addInterleavedVertexAndNormalArrays(GLArrayDataServer array,
- int components) {
- array.addFixedSubArray(GLPointerFunc.GL_VERTEX_ARRAY, 3, GL.GL_ARRAY_BUFFER);
- array.addFixedSubArray(GLPointerFunc.GL_NORMAL_ARRAY, 3, GL.GL_ARRAY_BUFFER);
+ public void addInterleavedVertexAndNormalArrays(GLArrayDataServer array, int components) {
+ array.addFixedSubArray(GLPointerFunc.GL_VERTEX_ARRAY, components, GL.GL_ARRAY_BUFFER);
+ array.addFixedSubArray(GLPointerFunc.GL_NORMAL_ARRAY, components, GL.GL_ARRAY_BUFFER);
}
private void draw(GL2ES1 gl, GLArrayDataServer array, int mode) {
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java
index 47feb60e2..c4864b521 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java
@@ -120,7 +120,7 @@ public class GearsES2 implements GLEventListener {
System.err.println("GL_VENDOR: " + gl.glGetString(GL.GL_VENDOR));
System.err.println("GL_RENDERER: " + gl.glGetString(GL.GL_RENDERER));
System.err.println("GL_VERSION: " + gl.glGetString(GL.GL_VERSION));
- System.err.println("GL GLSL: "+gl.hasGLSL()+", has-compiler: "+gl.isFunctionAvailable("glCompileShader")+", version "+(gl.hasGLSL() ? gl.glGetString(GL2ES2.GL_SHADING_LANGUAGE_VERSION) : "none"));
+ System.err.println("GL GLSL: "+gl.hasGLSL()+", has-compiler: "+gl.isFunctionAvailable("glCompileShader")+", version "+(gl.hasGLSL() ? gl.glGetString(GL2ES2.GL_SHADING_LANGUAGE_VERSION) : "none")+", "+gl.getContext().getGLSLVersionNumber());
System.err.println("GL FBO: basic "+ gl.hasBasicFBOSupport()+", full "+gl.hasFullFBOSupport());
System.err.println("GL Profile: "+gl.getGLProfile());
System.err.println("GL:" + gl + ", " + gl.getContext().getGLVersion());
@@ -130,9 +130,11 @@ public class GearsES2 implements GLEventListener {
st = new ShaderState();
// st.setVerbose(true);
final ShaderCode vp0 = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, this.getClass(), "shader",
- "shader/bin", "gears", false);
+ "shader/bin", "gears", true);
final ShaderCode fp0 = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, this.getClass(), "shader",
- "shader/bin", "gears", false);
+ "shader/bin", "gears", true);
+ vp0.defaultShaderCustomization(gl, true, ShaderCode.es2_default_precision_vp);
+ fp0.defaultShaderCustomization(gl, true, ShaderCode.es2_default_precision_fp);
final ShaderProgram sp0 = new ShaderProgram();
sp0.add(gl, vp0, System.err);
sp0.add(gl, fp0, System.err);
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsObjectES2.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsObjectES2.java
index bb526e350..e8b97e287 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsObjectES2.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsObjectES2.java
@@ -69,10 +69,9 @@ public class GearsObjectES2 extends GearsObject {
}
@Override
- public void addInterleavedVertexAndNormalArrays(GLArrayDataServer array,
- int components) {
- array.addGLSLSubArray("vertices", 3, GL.GL_ARRAY_BUFFER);
- array.addGLSLSubArray("normals", 3, GL.GL_ARRAY_BUFFER);
+ public void addInterleavedVertexAndNormalArrays(GLArrayDataServer array, int components) {
+ array.addGLSLSubArray("vertices", components, GL.GL_ARRAY_BUFFER);
+ array.addGLSLSubArray("normals", components, GL.GL_ARRAY_BUFFER);
}
private void draw(GL2ES2 gl, GLArrayDataServer array, int mode) {
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/PointsDemoES2.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/PointsDemoES2.java
index 27457e23c..1e0f9596f 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/PointsDemoES2.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/PointsDemoES2.java
@@ -58,20 +58,6 @@ public class PointsDemoES2 extends PointsDemo {
/** ( pointSize, pointSmooth, attn. pointMinSize, attn. pointMaxSize ) , ( attenuation coefficients 1f 0f 0f, attenuation fade theshold 1f ) */
private final FloatBuffer pointParams = Buffers.newDirectFloatBuffer(new float[] { 1.0f, 0.0f, 0.0f, 4096.0f, 1.0f, 0.0f, 0.0f, 1.0f });
- static final String es2_prelude_vp = "#version 100\n\nprecision highp float;\nprecision highp int;\n";
- static final String es2_prelude_fp = "#version 100\n\nprecision mediump float;\nprecision mediump int;\n/*precision lowp sampler2D;*/\n";
- static final String gl2_prelude = "#version 120\n"; // GL 2.1 (Nvidia driver claims it's required to use gl_Points, OSX claim's it for gl_PointCoord -> driver bug - both were introduced w/ 1.10)
-
- private void customizeShader(GL2ES2 gl, ShaderCode vp, ShaderCode fp) {
- if(gl.isGLES2()) {
- vp.insertShaderSource(0, 0, es2_prelude_vp);
- fp.insertShaderSource(0, 0, es2_prelude_fp);
- } else {
- vp.insertShaderSource(0, 0, gl2_prelude);
- fp.insertShaderSource(0, 0, gl2_prelude);
- }
- }
-
public PointsDemoES2(int swapInterval) {
this.swapInterval = swapInterval;
}
@@ -108,7 +94,8 @@ public class PointsDemoES2 extends PointsDemo {
"shader/bin", "PointsShader", true);
final ShaderCode fp0 = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, this.getClass(), "shader",
"shader/bin", "PointsShader", true);
- customizeShader(gl, vp0, fp0);
+ vp0.defaultShaderCustomization(gl, true, ShaderCode.es2_default_precision_vp);
+ fp0.defaultShaderCustomization(gl, true, ShaderCode.es2_default_precision_fp);
final ShaderProgram sp0 = new ShaderProgram();
sp0.add(gl, vp0, System.err);
sp0.add(gl, fp0, System.err);
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquareES2.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquareES2.java
index fea1d752e..a78ae17a9 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquareES2.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquareES2.java
@@ -86,9 +86,11 @@ public class RedSquareES2 implements GLEventListener {
st = new ShaderState();
st.setVerbose(true);
final ShaderCode vp0 = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, this.getClass(), "shader",
- "shader/bin", "RedSquareShader", false);
+ "shader/bin", "RedSquareShader", true);
final ShaderCode fp0 = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, this.getClass(), "shader",
- "shader/bin", "RedSquareShader", false);
+ "shader/bin", "RedSquareShader", true);
+ vp0.defaultShaderCustomization(gl, true, ShaderCode.es2_default_precision_vp);
+ fp0.defaultShaderCustomization(gl, true, ShaderCode.es2_default_precision_fp);
final ShaderProgram sp0 = new ShaderProgram();
sp0.add(gl, vp0, System.err);
sp0.add(gl, fp0, System.err);
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java
index 1620985c1..d2c00f980 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java
@@ -88,6 +88,7 @@ public class TestGearsES2NEWT extends UITestCase {
static int loops = 1;
static boolean loop_shutdown = false;
static boolean forceES2 = false;
+ static boolean forceGL3 = false;
@BeforeClass
public static void initClass() {
@@ -256,7 +257,15 @@ public class TestGearsES2NEWT extends UITestCase {
public void test01GL2ES2() throws InterruptedException {
for(int i=1; i<=loops; i++) {
System.err.println("Loop "+i+"/"+loops);
- GLCapabilities caps = new GLCapabilities(forceES2 ? GLProfile.get(GLProfile.GLES2) : GLProfile.getGL2ES2());
+ final GLProfile glp;
+ if(forceGL3) {
+ glp = GLProfile.get(GLProfile.GL3);
+ } else if(forceES2) {
+ glp = GLProfile.get(GLProfile.GLES2);
+ } else {
+ glp = GLProfile.getGL2ES2();
+ }
+ GLCapabilities caps = new GLCapabilities( glp );
caps.setBackgroundOpaque(opaque);
if(-1 < forceAlpha) {
caps.setAlphaBits(forceAlpha);
@@ -294,6 +303,8 @@ public class TestGearsES2NEWT extends UITestCase {
swapInterval = MiscUtils.atoi(args[i], swapInterval);
} else if(args[i].equals("-es2")) {
forceES2 = true;
+ } else if(args[i].equals("-gl3")) {
+ forceGL3 = true;
} else if(args[i].equals("-wait")) {
waitForKey = true;
} else if(args[i].equals("-mouseInvisible")) {
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/PointsShader.fp b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/PointsShader.fp
index 3e3be10b3..02efa1522 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/PointsShader.fp
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/PointsShader.fp
@@ -1,4 +1,11 @@
+#if __VERSION__ >= 140
+ #define varying in
+ out vec4 mgl_FragColor;
+#else
+ #define mgl_FragColor gl_FragColor
+#endif
+
// [0].rgba: 0, smooth, attnMinSz, attnMaxSz
// [1].rgba: attnCoeff(3), attnFadeTs
uniform vec4 mgl_PointParams[2];
@@ -28,12 +35,12 @@ void main (void)
#endif
#ifndef TEST
- gl_FragColor.a *= r1;
+ mgl_FragColor.a *= r1;
#else
- gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
- gl_FragColor.r = r1 < 0.0 ? 1.0 : 0.0;
- gl_FragColor.g = r > 1.0 ? 1.0 : 0.0;
- gl_FragColor.b = r > border ? 1.0 : 0.0;
+ mgl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
+ mgl_FragColor.r = r1 < 0.0 ? 1.0 : 0.0;
+ mgl_FragColor.g = r > 1.0 ? 1.0 : 0.0;
+ mgl_FragColor.b = r > border ? 1.0 : 0.0;
#endif
}
}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/PointsShader.vp b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/PointsShader.vp
index 5043a652b..873b1f834 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/PointsShader.vp
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/PointsShader.vp
@@ -1,4 +1,9 @@
+#if __VERSION__ >= 140
+ #define attribute in
+ #define varying out
+#endif
+
uniform vec4 mgl_ColorStatic;
uniform mat4 mgl_PMVMatrix[4]; // P, Mv, Mvi and Mvit (transpose(inverse(ModelView)) == normalMatrix)
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/RedSquareShader.fp b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/RedSquareShader.fp
index d3cfecd94..7cf059bae 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/RedSquareShader.fp
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/RedSquareShader.fp
@@ -1,23 +1,16 @@
// Copyright 2010 JogAmp Community. All rights reserved.
-/**
- * AMD complains: #version must occur before any other statement in the program
-#ifdef GL_ES
- #version 100
+#if __VERSION__ >= 140
+ #define varying in
+ out vec4 mgl_FragColor;
#else
- #version 110
-#endif
- */
-
-#ifdef GL_ES
- precision mediump float;
- precision mediump int;
+ #define mgl_FragColor gl_FragColor
#endif
varying vec4 frontColor;
void main (void)
{
- gl_FragColor = frontColor;
+ mgl_FragColor = frontColor;
}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/RedSquareShader.vp b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/RedSquareShader.vp
index bfd44c8f4..2b19f3251 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/RedSquareShader.vp
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/RedSquareShader.vp
@@ -1,17 +1,8 @@
// Copyright 2010 JogAmp Community. All rights reserved.
-/**
- * AMD complains: #version must occur before any other statement in the program
-#ifdef GL_ES
- #version 100
-#else
- #version 110
-#endif
- */
-
-#ifdef GL_ES
- precision mediump float;
- precision mediump int;
+#if __VERSION__ >= 140
+ #define attribute in
+ #define varying out
#endif
uniform mat4 mgl_PMVMatrix[2];
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/RedSquareShader2.fp b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/RedSquareShader2.fp
index 01e4b0964..e0b92db3b 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/RedSquareShader2.fp
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/RedSquareShader2.fp
@@ -1,26 +1,16 @@
// Copyright 2010 JogAmp Community. All rights reserved.
-/**
- * AMD complains: #version must occur before any other statement in the program
-#ifdef GL_ES
- #version 100
+#if __VERSION__ >= 140
+ #define varying in
+ out vec4 mgl_FragColor;
#else
- #version 110
-#endif
- */
-
-#ifdef GL_ES
- #define MEDIUMP mediump
- #define HIGHP highp
-#else
- #define MEDIUMP
- #define HIGHP
+ #define mgl_FragColor gl_FragColor
#endif
varying HIGHP vec4 frontColor;
void main (void)
{
- gl_FragColor = vec4(0.0, frontColor.g, frontColor.b, 1.0);
+ mgl_FragColor = vec4(0.0, frontColor.g, frontColor.b, 1.0);
}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/gears.fp b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/gears.fp
index f41addad8..b8e9e0eee 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/gears.fp
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/gears.fp
@@ -1,9 +1,11 @@
// Copyright (C) 2011 JogAmp Community. All rights reserved.
// Details see GearsES2.java
-#ifdef GL_ES
- precision mediump float;
- precision mediump int;
+#if __VERSION__ >= 140
+ #define varying in
+ out vec4 mgl_FragColor;
+#else
+ #define mgl_FragColor gl_FragColor
#endif
uniform vec4 color;
@@ -42,5 +44,5 @@ void main()
specular += color * pow(NdotHV, matShininess) * attenuation * matSpecular;
}
- gl_FragColor = ambient + diffuse + specular ;
+ mgl_FragColor = ambient + diffuse + specular ;
}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/gears.vp b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/gears.vp
index b2d77082b..e3a84b257 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/gears.vp
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/gears.vp
@@ -1,10 +1,11 @@
// Copyright (C) 2011 JogAmp Community. All rights reserved.
// Details see GearsES2.java
-#ifdef GL_ES
- precision mediump float;
- precision mediump int;
+#if __VERSION__ >= 140
+ #define attribute in
+ #define varying out
#endif
+
uniform mat4 pmvMatrix[4]; // P, Mv, Mvi and Mvit
uniform vec3 lightPos;