aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2012-10-14 09:59:22 +0200
committerSven Gothel <[email protected]>2012-10-14 09:59:22 +0200
commite658ab1e427a7957b9dbfa4a396506de6c6582fd (patch)
treecb3d8156a694dc763372e59e4abc3dc8907533db
parent842e9feefc9d1a885a92ad8f0068cbcbcdd0e3c4 (diff)
FixedFuncPipeline: Use ES2/GL2 prelude and set default precision. Shader code: Remove precision for default precision types.
-rw-r--r--src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncPipeline.java44
-rw-r--r--src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColor.fp2
-rw-r--r--src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColorTexture.fp10
-rw-r--r--src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_attribute.glsl22
-rw-r--r--src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_const.glsl2
-rw-r--r--src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_uniform.glsl6
6 files changed, 49 insertions, 37 deletions
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 d92a73cac..09f52e2a5 100644
--- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncPipeline.java
+++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncPipeline.java
@@ -741,10 +741,28 @@ public class FixedFuncPipeline {
return toString(null, DEBUG).toString();
}
- private static final String constMaxShader0 = "#define MAX_TEXTURE_UNITS 0\n";
- private static final String constMaxShader2 = "#define MAX_TEXTURE_UNITS 2\n";
- private static final String constMaxShader4 = "#define MAX_TEXTURE_UNITS 4\n";
- private static final String constMaxShader8 = "#define MAX_TEXTURE_UNITS 8\n";
+ // Shall we use: #ifdef GL_FRAGMENT_PRECISION_HIGH .. #endif for using highp in fragment shader if avail ?
+ 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 110\n";
+
+ private static final String constMaxTextures0 = "#define MAX_TEXTURE_UNITS 0\n";
+ private static final String constMaxTextures2 = "#define MAX_TEXTURE_UNITS 2\n";
+ private static final String constMaxTextures4 = "#define MAX_TEXTURE_UNITS 4\n";
+ private static final String constMaxTextures8 = "#define MAX_TEXTURE_UNITS 8\n";
+
+ private void customizeShader(GL2ES2 gl, ShaderCode vp, ShaderCode fp, String maxTextureDefine) {
+ int rsVpPos, rsFpPos;
+ if(gl.isGLES2()) {
+ rsVpPos = vp.insertShaderSource(0, 0, es2_prelude_vp);
+ rsFpPos = fp.insertShaderSource(0, 0, es2_prelude_fp);
+ } else {
+ rsVpPos = vp.insertShaderSource(0, 0, gl2_prelude);
+ rsFpPos = fp.insertShaderSource(0, 0, gl2_prelude);
+ }
+ vp.insertShaderSource(0, rsVpPos, maxTextureDefine);
+ fp.insertShaderSource(0, rsFpPos, maxTextureDefine);
+ }
private void loadShader(GL2ES2 gl, ShaderSelectionMode mode) {
final boolean loadColor = ShaderSelectionMode.COLOR == mode;
@@ -769,8 +787,7 @@ public class FixedFuncPipeline {
shaderBinRoot, vertexColorFile, true);
final ShaderCode fp = ShaderCode.create( gl, GL2ES2.GL_FRAGMENT_SHADER, shaderRootClass, shaderSrcRoot,
shaderBinRoot, fragmentColorFile, true);
- vp.insertShaderSource(0, 0, constMaxShader0);
- fp.insertShaderSource(0, 0, constMaxShader0);
+ customizeShader(gl, vp, fp, constMaxTextures0);
shaderProgramColor = new ShaderProgram();
shaderProgramColor.add(vp);
shaderProgramColor.add(fp);
@@ -783,8 +800,7 @@ public class FixedFuncPipeline {
shaderBinRoot, fragmentColorTextureFile, true);
if( loadColorTexture2 ) {
- vp.insertShaderSource(0, 0, constMaxShader2);
- fp.insertShaderSource(0, 0, constMaxShader2);
+ customizeShader(gl, vp, fp, constMaxTextures2);
shaderProgramColorTexture2 = new ShaderProgram();
shaderProgramColorTexture2.add(vp);
shaderProgramColorTexture2.add(fp);
@@ -792,8 +808,7 @@ public class FixedFuncPipeline {
throw new GLException("Couldn't link VertexColorTexture2 program: "+shaderProgramColorTexture2);
}
} else if( loadColorTexture4 ) {
- vp.insertShaderSource(0, 0, constMaxShader4);
- fp.insertShaderSource(0, 0, constMaxShader4);
+ customizeShader(gl, vp, fp, constMaxTextures4);
shaderProgramColorTexture4 = new ShaderProgram();
shaderProgramColorTexture4.add(vp);
shaderProgramColorTexture4.add(fp);
@@ -801,8 +816,7 @@ public class FixedFuncPipeline {
throw new GLException("Couldn't link VertexColorTexture4 program: "+shaderProgramColorTexture4);
}
} else if( loadColorTexture8 ) {
- vp.insertShaderSource(0, 0, constMaxShader8);
- fp.insertShaderSource(0, 0, constMaxShader8);
+ customizeShader(gl, vp, fp, constMaxTextures8);
shaderProgramColorTexture8 = new ShaderProgram();
shaderProgramColorTexture8.add(vp);
shaderProgramColorTexture8.add(fp);
@@ -815,8 +829,7 @@ public class FixedFuncPipeline {
shaderBinRoot, vertexColorLightFile, true);
final ShaderCode fp = ShaderCode.create( gl, GL2ES2.GL_FRAGMENT_SHADER, shaderRootClass, shaderSrcRoot,
shaderBinRoot, fragmentColorFile, true);
- vp.insertShaderSource(0, 0, constMaxShader0);
- fp.insertShaderSource(0, 0, constMaxShader0);
+ customizeShader(gl, vp, fp, constMaxTextures0);
shaderProgramColorLight = new ShaderProgram();
shaderProgramColorLight.add(vp);
shaderProgramColorLight.add(fp);
@@ -828,8 +841,7 @@ public class FixedFuncPipeline {
shaderBinRoot, vertexColorLightFile, true);
final ShaderCode fp = ShaderCode.create( gl, GL2ES2.GL_FRAGMENT_SHADER, shaderRootClass, shaderSrcRoot,
shaderBinRoot, fragmentColorTextureFile, true);
- vp.insertShaderSource(0, 0, constMaxShader8);
- fp.insertShaderSource(0, 0, constMaxShader8);
+ customizeShader(gl, vp, fp, constMaxTextures8);
shaderProgramColorTexture8Light = new ShaderProgram();
shaderProgramColorTexture8Light.add(vp);
shaderProgramColorTexture8Light.add(fp);
diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColor.fp b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColor.fp
index bd7f2bdb2..bb0ca0123 100644
--- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColor.fp
+++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColor.fp
@@ -7,7 +7,7 @@
void main (void)
{
- HIGHP vec4 color = frontColor;
+ vec4 color = frontColor;
if( mgl_CullFace > 0 &&
( ( MGL_FRONT == mgl_CullFace && gl_FrontFacing ) ||
diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColorTexture.fp b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColorTexture.fp
index 9d02a0f6c..2593dc750 100644
--- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColorTexture.fp
+++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColorTexture.fp
@@ -8,12 +8,12 @@
#include mgl_alphatest.fp
-const HIGHP float gamma = 1.5; // FIXME
-const HIGHP vec3 igammav = vec3(1.0 / gamma); // FIXME
+const float gamma = 1.5; // FIXME
+const vec3 igammav = vec3(1.0 / gamma); // FIXME
const vec4 texEnvColor = vec4(0.0); // FIXME
-const HIGHP vec4 zerov4 = vec4(0.0);
-const HIGHP vec4 onev4 = vec4(1.0);
+const vec4 zerov4 = vec4(0.0);
+const vec4 onev4 = vec4(1.0);
void calcTexColor(inout vec4 color, vec4 texColor, in int texFormat, in int texEnvMode) {
if(MGL_MODULATE == texEnvMode) { // default
@@ -51,7 +51,7 @@ void calcTexColor(inout vec4 color, vec4 texColor, in int texFormat, in int texE
void main (void)
{
- HIGHP vec4 color = frontColor;
+ vec4 color = frontColor;
if( mgl_CullFace > 0 &&
( ( MGL_FRONT == mgl_CullFace && gl_FrontFacing ) ||
diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_attribute.glsl b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_attribute.glsl
index 59dcb626f..f670f7b77 100644
--- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_attribute.glsl
+++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_attribute.glsl
@@ -4,22 +4,22 @@
#include es_precision.glsl
-attribute HIGHP vec4 mgl_Vertex;
-attribute HIGHP vec4 mgl_Normal;
-attribute HIGHP vec4 mgl_Color;
+attribute vec4 mgl_Vertex;
+attribute vec4 mgl_Normal;
+attribute vec4 mgl_Color;
#if MAX_TEXTURE_UNITS >= 2
-attribute HIGHP vec4 mgl_MultiTexCoord0;
-attribute HIGHP vec4 mgl_MultiTexCoord1;
+attribute vec4 mgl_MultiTexCoord0;
+attribute vec4 mgl_MultiTexCoord1;
#endif
#if MAX_TEXTURE_UNITS >= 4
-attribute HIGHP vec4 mgl_MultiTexCoord2;
-attribute HIGHP vec4 mgl_MultiTexCoord3;
+attribute vec4 mgl_MultiTexCoord2;
+attribute vec4 mgl_MultiTexCoord3;
#endif
#if MAX_TEXTURE_UNITS >= 8
-attribute HIGHP vec4 mgl_MultiTexCoord4;
-attribute HIGHP vec4 mgl_MultiTexCoord5;
-attribute HIGHP vec4 mgl_MultiTexCoord6;
-attribute HIGHP vec4 mgl_MultiTexCoord7;
+attribute vec4 mgl_MultiTexCoord4;
+attribute vec4 mgl_MultiTexCoord5;
+attribute vec4 mgl_MultiTexCoord6;
+attribute vec4 mgl_MultiTexCoord7;
#endif
#endif // mgl_attribute_glsl
diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_const.glsl b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_const.glsl
index e8b7d5d41..4f97292e3 100644
--- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_const.glsl
+++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_const.glsl
@@ -7,7 +7,7 @@
// will be defined at runtime: MAX_TEXTURE_UNITS [0|2|4|8]
const LOWP int MAX_LIGHTS = 8;
-const HIGHP float EPSILON = 0.0000001; // FIXME: determine proper hw-precision
+const float EPSILON = 0.0000001; // FIXME: determine proper hw-precision
// discard freezes NV tegra2 compiler (STILL TRUE?)
// #define DISCARD(c) (c.a = 0.0)
diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_uniform.glsl b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_uniform.glsl
index a2d91aa73..b92037ef9 100644
--- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_uniform.glsl
+++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_uniform.glsl
@@ -6,11 +6,11 @@
#include mgl_const.glsl
-uniform HIGHP mat4 mgl_PMVMatrix[4]; // P, Mv, Mvi and Mvit (transpose(inverse(ModelView)) == normalMatrix)
+uniform mat4 mgl_PMVMatrix[4]; // P, Mv, Mvi and Mvit (transpose(inverse(ModelView)) == normalMatrix)
uniform LOWP int mgl_ColorEnabled;
-uniform HIGHP vec4 mgl_ColorStatic;
+uniform vec4 mgl_ColorStatic;
uniform LOWP int mgl_AlphaTestFunc;
-uniform HIGHP float mgl_AlphaTestRef;
+uniform float mgl_AlphaTestRef;
#if MAX_TEXTURE_UNITS > 0
uniform LOWP int mgl_TextureEnabled[MAX_TEXTURE_UNITS];
uniform LOWP int mgl_TexCoordEnabled[MAX_TEXTURE_UNITS];