From acdb3d4cbbdd6ade5d347abaaac71a1a8abe48e1 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sat, 13 Oct 2012 21:30:51 +0200 Subject: FixedFuncPipeline: Optimize shader resource, if preset != ShaderSelectionMode.AUTO (good for mobile); Lazy shader instantiation. --- .../opengl/util/glsl/fixedfunc/shaders/FixedFuncColorTexture.fp | 6 ++++++ .../jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_attribute.glsl | 6 ++++++ .../jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_const.glsl | 2 +- .../jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_settexcoord.vp | 6 ++++++ .../jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_uniform.glsl | 9 ++++++++- .../jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_varying.glsl | 2 ++ 6 files changed, 29 insertions(+), 2 deletions(-) (limited to 'src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders') 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 edaa00a57..9d02a0f6c 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 @@ -61,18 +61,23 @@ void main (void) } else { int texEnv = 0; + #if MAX_TEXTURE_UNITS >= 2 if( 0 != mgl_TextureEnabled[0] ) { calcTexColor(color, texture2D(mgl_Texture0, mgl_TexCoords[0].st), mgl_TexFormat[0], mgl_TexEnvMode[0]); } if( 0 != mgl_TextureEnabled[1] ) { calcTexColor(color, texture2D(mgl_Texture1, mgl_TexCoords[1].st), mgl_TexFormat[1], mgl_TexEnvMode[1]); } + #endif + #if MAX_TEXTURE_UNITS >= 4 if( 0 != mgl_TextureEnabled[2] ) { calcTexColor(color, texture2D(mgl_Texture2, mgl_TexCoords[2].st), mgl_TexFormat[2], mgl_TexEnvMode[2]); } if( 0 != mgl_TextureEnabled[3] ) { calcTexColor(color, texture2D(mgl_Texture3, mgl_TexCoords[3].st), mgl_TexFormat[3], mgl_TexEnvMode[3]); } + #endif + #if MAX_TEXTURE_UNITS >= 8 if( 0 != mgl_TextureEnabled[4] ) { calcTexColor(color, texture2D(mgl_Texture4, mgl_TexCoords[4].st), mgl_TexFormat[4], mgl_TexEnvMode[4]); } @@ -85,6 +90,7 @@ void main (void) if( 0 != mgl_TextureEnabled[7] ) { calcTexColor(color, texture2D(mgl_Texture7, mgl_TexCoords[7].st), mgl_TexFormat[7], mgl_TexEnvMode[7]); } + #endif if( mgl_AlphaTestFunc > 0 ) { alphaTest(color); } 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 09a11ec95..59dcb626f 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 @@ -7,13 +7,19 @@ attribute HIGHP vec4 mgl_Vertex; attribute HIGHP vec4 mgl_Normal; attribute HIGHP vec4 mgl_Color; +#if MAX_TEXTURE_UNITS >= 2 attribute HIGHP vec4 mgl_MultiTexCoord0; attribute HIGHP vec4 mgl_MultiTexCoord1; +#endif +#if MAX_TEXTURE_UNITS >= 4 attribute HIGHP vec4 mgl_MultiTexCoord2; attribute HIGHP 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; +#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 d45b593e2..e8b7d5d41 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 @@ -4,7 +4,7 @@ #include es_precision.glsl -const LOWP int MAX_TEXTURE_UNITS = 8; // <=gl_MaxTextureImageUnits +// 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 diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_settexcoord.vp b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_settexcoord.vp index 1efe328d0..cbf0db642 100644 --- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_settexcoord.vp +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_settexcoord.vp @@ -22,14 +22,20 @@ void setTexCoord(in vec4 defpos) { mgl_TexCoords[7] = ( 0 != (mgl_TexCoordEnabled & 128) ) ? mgl_MultiTexCoord7 : defpos; */ + #if MAX_TEXTURE_UNITS >= 2 mgl_TexCoords[0] = ( 0 != mgl_TexCoordEnabled[0] ) ? mgl_MultiTexCoord0 : defpos; mgl_TexCoords[1] = ( 0 != mgl_TexCoordEnabled[1] ) ? mgl_MultiTexCoord1 : defpos; + #endif + #if MAX_TEXTURE_UNITS >= 4 mgl_TexCoords[2] = ( 0 != mgl_TexCoordEnabled[2] ) ? mgl_MultiTexCoord2 : defpos; mgl_TexCoords[3] = ( 0 != mgl_TexCoordEnabled[3] ) ? mgl_MultiTexCoord3 : defpos; + #endif + #if MAX_TEXTURE_UNITS >= 8 mgl_TexCoords[4] = ( 0 != mgl_TexCoordEnabled[4] ) ? mgl_MultiTexCoord4 : defpos; mgl_TexCoords[5] = ( 0 != mgl_TexCoordEnabled[5] ) ? mgl_MultiTexCoord5 : defpos; mgl_TexCoords[6] = ( 0 != mgl_TexCoordEnabled[6] ) ? mgl_MultiTexCoord6 : defpos; mgl_TexCoords[7] = ( 0 != mgl_TexCoordEnabled[7] ) ? mgl_MultiTexCoord7 : defpos; + #endif } #endif // mgl_settexcoord_vp 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 aeaa1314d..a2d91aa73 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 @@ -11,19 +11,26 @@ uniform LOWP int mgl_ColorEnabled; uniform HIGHP vec4 mgl_ColorStatic; uniform LOWP int mgl_AlphaTestFunc; uniform HIGHP float mgl_AlphaTestRef; +#if MAX_TEXTURE_UNITS > 0 uniform LOWP int mgl_TextureEnabled[MAX_TEXTURE_UNITS]; uniform LOWP int mgl_TexCoordEnabled[MAX_TEXTURE_UNITS]; uniform LOWP int mgl_TexEnvMode[MAX_TEXTURE_UNITS]; uniform LOWP int mgl_TexFormat[MAX_TEXTURE_UNITS]; +#if MAX_TEXTURE_UNITS >= 2 uniform sampler2D mgl_Texture0; uniform sampler2D mgl_Texture1; +#endif +#if MAX_TEXTURE_UNITS >= 4 uniform sampler2D mgl_Texture2; uniform sampler2D mgl_Texture3; +#endif +#if MAX_TEXTURE_UNITS >= 8 uniform sampler2D mgl_Texture4; uniform sampler2D mgl_Texture5; uniform sampler2D mgl_Texture6; uniform sampler2D mgl_Texture7; -uniform sampler2D mgl_Texture8; +#endif +#endif uniform LOWP int mgl_CullFace; #endif // mgl_uniform_glsl diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_varying.glsl b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_varying.glsl index fc9f735d1..599ac4a53 100644 --- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_varying.glsl +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_varying.glsl @@ -7,6 +7,8 @@ #include mgl_const.glsl varying vec4 frontColor; +#if MAX_TEXTURE_UNITS > 0 varying vec4 mgl_TexCoords[MAX_TEXTURE_UNITS]; +#endif #endif // mgl_varying_glsl -- cgit v1.2.3