From bf0d4a8840addbd099b7b771c25f7135c64132a8 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 29 Oct 2012 11:52:15 +0100 Subject: FixedFuncPipeline: Use proper shader version and make GLSL code compatible w/ higher GLSL versions --- .../com/jogamp/opengl/util/glsl/ShaderCode.java | 1 + .../util/glsl/fixedfunc/FixedFuncPipeline.java | 21 +++++---------------- .../util/glsl/fixedfunc/shaders/FixedFuncColor.fp | 10 +++++++++- .../util/glsl/fixedfunc/shaders/FixedFuncColor.vp | 6 ++++++ .../glsl/fixedfunc/shaders/FixedFuncColorLight.vp | 6 ++++++ .../glsl/fixedfunc/shaders/FixedFuncColorTexture.fp | 14 +++++++++++--- .../util/glsl/fixedfunc/shaders/FixedFuncPoints.fp | 20 ++++++++++++++------ .../util/glsl/fixedfunc/shaders/FixedFuncPoints.vp | 6 ++++++ 8 files changed, 58 insertions(+), 26 deletions(-) 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 378167c2c..e6dde3237 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java +++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java @@ -807,6 +807,7 @@ public class ShaderCode { } } + // Shall we use: #ifdef GL_FRAGMENT_PRECISION_HIGH .. #endif for using highp in fragment shader if avail ? /** {@value #es2_default_precision_vp} */ public static final String es2_default_precision_vp = "\nprecision highp float;\nprecision highp int;\n"; /** {@value #es2_default_precision_fp} */ 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 716787b02..cc58f2363 100644 --- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncPipeline.java +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncPipeline.java @@ -937,30 +937,19 @@ public class FixedFuncPipeline { return toString(null, DEBUG).toString(); } - // 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 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 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); - } + private final void customizeShader(GL2ES2 gl, ShaderCode vp, ShaderCode fp, String maxTextureDefine) { + int rsVpPos = vp.defaultShaderCustomization(gl, true, ShaderCode.es2_default_precision_vp); + int rsFpPos = fp.defaultShaderCustomization(gl, true, ShaderCode.es2_default_precision_fp); vp.insertShaderSource(0, rsVpPos, maxTextureDefine); fp.insertShaderSource(0, rsFpPos, maxTextureDefine); } - private void loadShaderPoints(GL2ES2 gl) { + private final void loadShaderPoints(GL2ES2 gl) { if( null != shaderProgramPoints ) { return; } @@ -978,7 +967,7 @@ public class FixedFuncPipeline { } } - private void loadShader(GL2ES2 gl, ShaderSelectionMode mode) { + private final void loadShader(GL2ES2 gl, ShaderSelectionMode mode) { final boolean loadColor = ShaderSelectionMode.COLOR == mode; final boolean loadColorTexture2 = ShaderSelectionMode.COLOR_TEXTURE2 == mode; final boolean loadColorTexture4 = ShaderSelectionMode.COLOR_TEXTURE4 == mode; 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 0ed10b345..22dd1e61a 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 @@ -1,3 +1,11 @@ + +#if __VERSION__ >= 130 + #define varying in + out vec4 mgl_FragColor; +#else + #define mgl_FragColor gl_FragColor +#endif + #include es_precision.glsl #include mgl_uniform.glsl @@ -19,6 +27,6 @@ void main (void) if( mgl_AlphaTestFunc > 0 ) { alphaTest(color); } - gl_FragColor = color; + mgl_FragColor = color; } diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColor.vp b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColor.vp index 346e40196..f39fcfbd0 100644 --- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColor.vp +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColor.vp @@ -1,3 +1,9 @@ + +#if __VERSION__ >= 130 + #define attribute in + #define varying out +#endif + #include es_precision.glsl #include mgl_const.glsl diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColorLight.vp b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColorLight.vp index 0b5519355..942a540af 100644 --- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColorLight.vp +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColorLight.vp @@ -1,3 +1,9 @@ + +#if __VERSION__ >= 130 + #define attribute in + #define varying out +#endif + #include es_precision.glsl #include mgl_lightdef.glsl 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 9a7e5217b..82dfa24e1 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 @@ -1,4 +1,12 @@ +#if __VERSION__ >= 130 + #define varying in + out vec4 mgl_FragColor; +#else + #define mgl_FragColor gl_FragColor +#endif + + #include es_precision.glsl #include mgl_lightdef.glsl @@ -95,14 +103,14 @@ void main (void) } // } /* CullFace */ - gl_FragColor = color; + mgl_FragColor = color; /** // simple alpha check if (color.a != 0.0) { - gl_FragColor = vec4(pow(color.rgb, igammav), color.a); + mgl_FragColor = vec4(pow(color.rgb, igammav), color.a); } else { // discard; // freezes NV tegra2 compiler - gl_FragColor = color; + mgl_FragColor = color; } */ } diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncPoints.fp b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncPoints.fp index 6185e96ef..2d58f2320 100644 --- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncPoints.fp +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncPoints.fp @@ -1,4 +1,12 @@ +#if __VERSION__ >= 130 + #define varying in + out vec4 mgl_FragColor; +#else + #define mgl_FragColor gl_FragColor +#endif + + #include es_precision.glsl #include mgl_lightdef.glsl @@ -10,7 +18,7 @@ void main (void) { - gl_FragColor = frontColor; + mgl_FragColor = frontColor; if( pointSmooth > 0.5 ) { // smooth (AA) @@ -27,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/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncPoints.vp b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncPoints.vp index 64732dc9e..4a5d93a3d 100644 --- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncPoints.vp +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncPoints.vp @@ -1,3 +1,9 @@ + +#if __VERSION__ >= 130 + #define attribute in + #define varying out +#endif + #include es_precision.glsl #include mgl_const.glsl -- cgit v1.2.3