From e3ee1e25276760cba5db0333301d3ba19d62dd69 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 12 Oct 2012 15:10:29 +0200 Subject: Enhance FixedFuncPipeline: Multi-Texture, Tex-Env, Alpha-Test, Lighting (fix, incomplete still), ShaderSelectionMode, Fix default values Besides the above mentioned additional features towards completness of the FFP emu, the ShaderSelectionMode allows fixating a shader program configuration, i.e. AUTO switch (default) or choosing a static shader program to avoid heavy program switches incl. uniform/attribute updates. --- .../util/glsl/fixedfunc/shaders/FixedFuncColor.fp | 19 ++-- .../glsl/fixedfunc/shaders/FixedFuncColorLight.vp | 10 +- .../fixedfunc/shaders/FixedFuncColorTexture.fp | 118 +++++++++++++++------ .../util/glsl/fixedfunc/shaders/mgl_alphatest.fp | 33 ++++++ .../util/glsl/fixedfunc/shaders/mgl_const.glsl | 29 +++++ .../util/glsl/fixedfunc/shaders/mgl_lightdef.glsl | 3 + .../util/glsl/fixedfunc/shaders/mgl_uniform.glsl | 16 ++- .../glsl/fixedfunc/shaders/mgl_uniform_light.glsl | 1 + 8 files changed, 186 insertions(+), 43 deletions(-) create mode 100644 src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_alphatest.fp (limited to 'src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders') 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 408ff7251..bd7f2bdb2 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 @@ -3,14 +3,21 @@ #include mgl_uniform.glsl #include mgl_varying.glsl +#include mgl_alphatest.fp + void main (void) { - if( mgl_CullFace > 0 && - ( ( mgl_CullFace == 1 && gl_FrontFacing ) || - ( mgl_CullFace == 2 && !gl_FrontFacing ) || - ( mgl_CullFace == 3 ) ) ) { - discard; + HIGHP vec4 color = frontColor; + + if( mgl_CullFace > 0 && + ( ( MGL_FRONT == mgl_CullFace && gl_FrontFacing ) || + ( MGL_BACK == mgl_CullFace && !gl_FrontFacing ) || + ( MGL_FRONT_AND_BACK == mgl_CullFace ) ) ) { + DISCARD(color); + } + if( mgl_AlphaTestFunc > 0 ) { + alphaTest(color); } - gl_FragColor = frontColor; + gl_FragColor = color; } 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 7ce1eedcf..0b5519355 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 @@ -50,16 +50,18 @@ void main(void) } } } - ambient *= mgl_FrontMaterial.ambient; - diffuse *= mgl_FrontMaterial.diffuse; - specular *= mgl_FrontMaterial.specular; - if(mgl_ColorEnabled>0) { frontColor=mgl_Color; } else { frontColor=mgl_ColorStatic; } if( lightEnabled ) { + // light-ambient + global-ambient + // ( mgl_LightSource[0..n].ambient * mgl_FrontMaterial.ambient ) + ( mgl_LightModel.ambient * mgl_FrontMaterial.ambient ) + ambient = ( ambient + mgl_LightModel.ambient ) * mgl_FrontMaterial.ambient; + diffuse *= mgl_FrontMaterial.diffuse; + specular *= mgl_FrontMaterial.specular; + frontColor *= ambient + diffuse + specular; } 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 86e6ace73..edaa00a57 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 @@ -6,42 +6,98 @@ #include mgl_uniform.glsl #include mgl_varying.glsl -vec4 getTexColor(in sampler2D tex, in int idx) { - vec4 coord; - if(idx==0) { - coord= mgl_TexCoords[0]; - } else if(idx==1) { - coord= mgl_TexCoords[1]; - } else if(idx==2) { - coord= mgl_TexCoords[2]; - } else if(idx==3) { - coord= mgl_TexCoords[3]; - } else if(idx==4) { - coord= mgl_TexCoords[4]; - } else if(idx==5) { - coord= mgl_TexCoords[5]; - } else if(idx==6) { - coord= mgl_TexCoords[6]; - } else { - coord= mgl_TexCoords[7]; +#include mgl_alphatest.fp + +const HIGHP float gamma = 1.5; // FIXME +const HIGHP 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); + +void calcTexColor(inout vec4 color, vec4 texColor, in int texFormat, in int texEnvMode) { + if(MGL_MODULATE == texEnvMode) { // default + if( 4 == texFormat ) { + color *= texColor; + } else { + color.rgb *= texColor.rgb; + } + } else if(MGL_REPLACE == texEnvMode) { + if( 4 == texFormat ) { + color = texColor; + } else { + color.rgb = texColor.rgb; + } + } else if(MGL_ADD == texEnvMode) { + if( 4 == texFormat ) { + color += texColor; + } else { + color.rgb += texColor.rgb; + } + } else if(MGL_BLEND == texEnvMode) { + color.rgb = mix(color.rgb, texEnvColor.rgb, texColor.rgb); + if( 4 == texFormat ) { + color.a *= texColor.a; + } + } else if(MGL_DECAL == texEnvMode) { + if( 4 == texFormat ) { + color.rgb = mix(color.rgb, texColor.rgb, texColor.a); + } else { + color.rgb = texColor.rgb; + } } - return texture2D(tex, coord.st); + color = clamp(color, zerov4, onev4); } void main (void) -{ - if( mgl_CullFace > 0 && - ( ( mgl_CullFace == 1 && gl_FrontFacing ) || - ( mgl_CullFace == 2 && !gl_FrontFacing ) || - ( mgl_CullFace == 3 ) ) ) { - discard; - } - - vec4 texColor = getTexColor(mgl_ActiveTexture,mgl_ActiveTextureIdx); +{ + HIGHP vec4 color = frontColor; - if(length(texColor.rgb)>0.0) { - gl_FragColor = vec4(frontColor.rgb*texColor.rgb, frontColor.a) ; + if( mgl_CullFace > 0 && + ( ( MGL_FRONT == mgl_CullFace && gl_FrontFacing ) || + ( MGL_BACK == mgl_CullFace && !gl_FrontFacing ) || + ( MGL_FRONT_AND_BACK == mgl_CullFace ) ) ) { + DISCARD(color); } else { - gl_FragColor = frontColor; + int texEnv = 0; + + 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]); + } + 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]); + } + if( 0 != mgl_TextureEnabled[4] ) { + calcTexColor(color, texture2D(mgl_Texture4, mgl_TexCoords[4].st), mgl_TexFormat[4], mgl_TexEnvMode[4]); + } + if( 0 != mgl_TextureEnabled[5] ) { + calcTexColor(color, texture2D(mgl_Texture5, mgl_TexCoords[5].st), mgl_TexFormat[5], mgl_TexEnvMode[5]); + } + if( 0 != mgl_TextureEnabled[6] ) { + calcTexColor(color, texture2D(mgl_Texture6, mgl_TexCoords[6].st), mgl_TexFormat[6], mgl_TexEnvMode[6]); + } + if( 0 != mgl_TextureEnabled[7] ) { + calcTexColor(color, texture2D(mgl_Texture7, mgl_TexCoords[7].st), mgl_TexFormat[7], mgl_TexEnvMode[7]); + } + if( mgl_AlphaTestFunc > 0 ) { + alphaTest(color); + } } + + gl_FragColor = color; + /** + // simple alpha check + if (color.a != 0.0) { + gl_FragColor = vec4(pow(color.rgb, igammav), color.a); + } else { + // discard; // freezes NV tegra2 compiler + gl_FragColor = color; + } */ } + diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_alphatest.fp b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_alphatest.fp new file mode 100644 index 000000000..2b64cdeb8 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_alphatest.fp @@ -0,0 +1,33 @@ + +void alphaTest(inout vec4 color) { + if( MGL_GREATER == mgl_AlphaTestFunc ) { + if ( color.a <= mgl_AlphaTestRef ) { + DISCARD(color); + } + } else if( MGL_LESS == mgl_AlphaTestFunc ) { + if ( color.a >= mgl_AlphaTestRef ) { + DISCARD(color); + } + } else if( MGL_LEQUAL == mgl_AlphaTestFunc ) { + if ( color.a > mgl_AlphaTestRef ) { + DISCARD(color); + } + } else if( MGL_GEQUAL == mgl_AlphaTestFunc ) { + if ( color.a < mgl_AlphaTestRef ) { + DISCARD(color); + } + } else if( MGL_EQUAL == mgl_AlphaTestFunc ) { + if ( abs( color.a - mgl_AlphaTestRef ) > EPSILON ) { + DISCARD(color); + } + } else if( MGL_NOTEQUAL == mgl_AlphaTestFunc ) { + if ( abs( color.a - mgl_AlphaTestRef ) <= EPSILON ) { + DISCARD(color); + } + } else if( MGL_NEVER == mgl_AlphaTestFunc ) { + DISCARD(color); + } /* else if( MGL_ALWAYS == mgl_AlphaTestFunc ) { + // NOP + } */ +} + 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 1a464a1cb..d45b593e2 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,4 +7,33 @@ const LOWP int MAX_TEXTURE_UNITS = 8; // <=gl_MaxTextureImageUnits const LOWP int MAX_LIGHTS = 8; +const HIGHP float EPSILON = 0.0000001; // FIXME: determine proper hw-precision + +// discard freezes NV tegra2 compiler (STILL TRUE?) +// #define DISCARD(c) (c.a = 0.0) +#define DISCARD(c) discard + +// Texture Environment / Multi Texturing +#define MGL_ADD 1 +#define MGL_MODULATE 2 +#define MGL_DECAL 3 +#define MGL_BLEND 4 +#define MGL_REPLACE 5 +#define MGL_COMBINE 6 + +// Alpha Test +#define MGL_NEVER 1 +#define MGL_LESS 2 +#define MGL_EQUAL 3 +#define MGL_LEQUAL 4 +#define MGL_GREATER 5 +#define MGL_NOTEQUAL 6 +#define MGL_GEQUAL 7 +#define MGL_ALWAYS 8 + +// Cull Face +#define MGL_FRONT 1 +#define MGL_BACK 2 +#define MGL_FRONT_AND_BACK 3 + #endif // mgl_const_glsl diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_lightdef.glsl b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_lightdef.glsl index 98e214139..deaf95408 100644 --- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_lightdef.glsl +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_lightdef.glsl @@ -1,6 +1,9 @@ #ifndef mgl_lightdef_glsl #define mgl_lightdef_glsl +struct mgl_LightModelParameters { + vec4 ambient; +}; struct mgl_LightSourceParameters { vec4 ambient; vec4 diffuse; 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 4c4000dfa..aeaa1314d 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 @@ -9,9 +9,21 @@ uniform HIGHP mat4 mgl_PMVMatrix[4]; // P, Mv, Mvi and Mvit (transpose(inverse(ModelView)) == normalMatrix) uniform LOWP int mgl_ColorEnabled; uniform HIGHP vec4 mgl_ColorStatic; +uniform LOWP int mgl_AlphaTestFunc; +uniform HIGHP float mgl_AlphaTestRef; +uniform LOWP int mgl_TextureEnabled[MAX_TEXTURE_UNITS]; uniform LOWP int mgl_TexCoordEnabled[MAX_TEXTURE_UNITS]; -uniform sampler2D mgl_ActiveTexture; -uniform LOWP int mgl_ActiveTextureIdx; +uniform LOWP int mgl_TexEnvMode[MAX_TEXTURE_UNITS]; +uniform LOWP int mgl_TexFormat[MAX_TEXTURE_UNITS]; +uniform sampler2D mgl_Texture0; +uniform sampler2D mgl_Texture1; +uniform sampler2D mgl_Texture2; +uniform sampler2D mgl_Texture3; +uniform sampler2D mgl_Texture4; +uniform sampler2D mgl_Texture5; +uniform sampler2D mgl_Texture6; +uniform sampler2D mgl_Texture7; +uniform sampler2D mgl_Texture8; uniform LOWP int mgl_CullFace; #endif // mgl_uniform_glsl diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_uniform_light.glsl b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_uniform_light.glsl index 0dedb5d5d..5b34fd9cf 100644 --- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_uniform_light.glsl +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_uniform_light.glsl @@ -9,6 +9,7 @@ uniform LOWP int mgl_LightsEnabled[MAX_LIGHTS]; +uniform mgl_LightModelParameters mgl_LightModel; uniform mgl_LightSourceParameters mgl_LightSource[MAX_LIGHTS]; uniform mgl_MaterialParameters mgl_FrontMaterial; -- cgit v1.2.3 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. --- .../util/glsl/fixedfunc/ShaderSelectionMode.java | 12 +- .../util/glsl/fixedfunc/FixedFuncPipeline.java | 255 ++++++++++++++------- .../fixedfunc/shaders/FixedFuncColorTexture.fp | 6 + .../util/glsl/fixedfunc/shaders/mgl_attribute.glsl | 6 + .../util/glsl/fixedfunc/shaders/mgl_const.glsl | 2 +- .../util/glsl/fixedfunc/shaders/mgl_settexcoord.vp | 6 + .../util/glsl/fixedfunc/shaders/mgl_uniform.glsl | 9 +- .../util/glsl/fixedfunc/shaders/mgl_varying.glsl | 2 + 8 files changed, 214 insertions(+), 84 deletions(-) (limited to 'src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders') diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/fixedfunc/ShaderSelectionMode.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/fixedfunc/ShaderSelectionMode.java index fba4b755e..e6bdf702c 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/glsl/fixedfunc/ShaderSelectionMode.java +++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/fixedfunc/ShaderSelectionMode.java @@ -14,10 +14,14 @@ public enum ShaderSelectionMode { AUTO, /** Fixed shader selection: Simple color. */ COLOR, - /** Fixed shader selection: Multi-Textured color. */ - COLOR_TEXTURE, + /** Fixed shader selection: Multi-Textured color. 2 texture units. */ + COLOR_TEXTURE2, + /** Fixed shader selection: Multi-Textured color. 4 texture units. */ + COLOR_TEXTURE4, + /** Fixed shader selection: Multi-Textured color. 8 texture units. */ + COLOR_TEXTURE8, /** Fixed shader selection: Color with vertex-lighting. */ COLOR_LIGHT_PER_VERTEX, - /** Fixed shader selection: Multi-Textured color with vertex-lighting. */ - COLOR_TEXTURE_LIGHT_PER_VERTEX + /** Fixed shader selection: Multi-Textured color with vertex-lighting. 8 texture units.*/ + COLOR_TEXTURE8_LIGHT_PER_VERTEX } \ No newline at end of file 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 be9fe8c34..b7097b0fd 100644 --- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncPipeline.java +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncPipeline.java @@ -62,20 +62,33 @@ import com.jogamp.opengl.util.glsl.fixedfunc.ShaderSelectionMode; */ public class FixedFuncPipeline { protected static final boolean DEBUG = Debug.isPropertyDefined("jogl.debug.FixedFuncPipeline", true); + /** The maximum texture units which could be used, depending on {@link ShaderSelectionMode}. */ public static final int MAX_TEXTURE_UNITS = 8; public static final int MAX_LIGHTS = 8; public FixedFuncPipeline(GL2ES2 gl, ShaderSelectionMode mode, PMVMatrix pmvMatrix) { - init(gl, mode, pmvMatrix, FixedFuncPipeline.class, shaderSrcRootDef, - shaderBinRootDef, vertexColorFileDef, vertexColorLightFileDef, fragmentColorFileDef, fragmentColorTextureFileDef); - } - public FixedFuncPipeline(GL2ES2 gl, ShaderSelectionMode mode, PMVMatrix pmvMatrix, Class shaderRootClass, String shaderSrcRoot, - String shaderBinRoot, - String vertexColorFile, - String vertexColorLightFile, - String fragmentColorFile, String fragmentColorTextureFile) { - init(gl, mode, pmvMatrix, shaderRootClass, shaderSrcRoot, - shaderBinRoot, vertexColorFile, vertexColorLightFile, fragmentColorFile, fragmentColorTextureFile); + shaderRootClass = FixedFuncPipeline.class; + shaderSrcRoot = shaderSrcRootDef; + shaderBinRoot = shaderBinRootDef; + vertexColorFile = vertexColorFileDef; + vertexColorLightFile = vertexColorLightFileDef; + fragmentColorFile = fragmentColorFileDef; + fragmentColorTextureFile = fragmentColorTextureFileDef; + init(gl, mode, pmvMatrix); + } + public FixedFuncPipeline(GL2ES2 gl, ShaderSelectionMode mode, PMVMatrix pmvMatrix, + Class shaderRootClass, String shaderSrcRoot, + String shaderBinRoot, + String vertexColorFile, String vertexColorLightFile, + String fragmentColorFile, String fragmentColorTextureFile) { + this.shaderRootClass = shaderRootClass; + this.shaderSrcRoot = shaderSrcRoot; + this.shaderBinRoot = shaderBinRoot; + this.vertexColorFile = vertexColorFile; + this.vertexColorLightFile = vertexColorLightFile; + this.fragmentColorFile = fragmentColorFile; + this.fragmentColorTextureFile = fragmentColorTextureFile; + init(gl, mode, pmvMatrix); } public ShaderSelectionMode getShaderSelectionMode() { return shaderSelectionMode; } @@ -98,10 +111,24 @@ public class FixedFuncPipeline { } public void destroy(GL2ES2 gl) { - shaderProgramColor.release(gl, true); - shaderProgramColorLight.release(gl, true); - shaderProgramColorTexture.release(gl, true); - shaderProgramColorTextureLight.release(gl, true); + if(null != shaderProgramColor) { + shaderProgramColor.release(gl, true); + } + if(null != shaderProgramColorLight) { + shaderProgramColorLight.release(gl, true); + } + if(null != shaderProgramColorTexture2) { + shaderProgramColorTexture2.release(gl, true); + } + if(null != shaderProgramColorTexture4) { + shaderProgramColorTexture4.release(gl, true); + } + if(null != shaderProgramColorTexture4) { + shaderProgramColorTexture4.release(gl, true); + } + if(null != shaderProgramColorTexture8Light) { + shaderProgramColorTexture8Light.release(gl, true); + } shaderState.destroy(gl); } @@ -562,9 +589,10 @@ public class FixedFuncPipeline { // pre-validate shader switch if( 0 != textureEnabledBits ) { if(lightingEnabled) { - newMode = ShaderSelectionMode.COLOR_TEXTURE_LIGHT_PER_VERTEX; + newMode = ShaderSelectionMode.COLOR_TEXTURE8_LIGHT_PER_VERTEX; } else { - newMode = ShaderSelectionMode.COLOR_TEXTURE; + // in auto mode, we simply use max texture units + newMode = ShaderSelectionMode.COLOR_TEXTURE8; } } else { if(lightingEnabled) { @@ -683,9 +711,11 @@ public class FixedFuncPipeline { sb.append("\n\t lightingEnabled: "+lightingEnabled); sb.append(", lightsEnabled: "); Buffers.toString(sb, null, lightsEnabled); sb.append("\n\t, shaderProgramColor: "+shaderProgramColor); - sb.append("\n\t, shaderProgramColorTexture: "+shaderProgramColorTexture); + sb.append("\n\t, shaderProgramColorTexture2: "+shaderProgramColorTexture2); + sb.append("\n\t, shaderProgramColorTexture4: "+shaderProgramColorTexture4); + sb.append("\n\t, shaderProgramColorTexture8: "+shaderProgramColorTexture8); sb.append("\n\t, shaderProgramColorLight: "+shaderProgramColorLight); - sb.append("\n\t, shaderProgramColorTextureLight: "+shaderProgramColorTextureLight); + sb.append("\n\t, shaderProgramColorTexture8Light: "+shaderProgramColorTexture8Light); sb.append("\n\t, ShaderState: "); shaderState.toString(sb, alsoUnlocated); sb.append("]"); @@ -695,19 +725,126 @@ 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"; + + private 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; + final boolean loadColorTexture8 = ShaderSelectionMode.COLOR_TEXTURE8 == mode; + final boolean loadColorTexture = loadColorTexture2 || loadColorTexture4 || loadColorTexture8 ; + final boolean loadColorLightPerVertex = ShaderSelectionMode.COLOR_LIGHT_PER_VERTEX == mode; + final boolean loadColorTexture8LightPerVertex = ShaderSelectionMode.COLOR_TEXTURE8_LIGHT_PER_VERTEX == mode; + + if( null != shaderProgramColor && loadColor || + null != shaderProgramColorTexture2 && loadColorTexture2 || + null != shaderProgramColorTexture4 && loadColorTexture4 || + null != shaderProgramColorTexture8 && loadColorTexture8 || + null != shaderProgramColorLight && loadColorLightPerVertex || + null != shaderProgramColorTexture8Light && loadColorTexture8LightPerVertex ) { + return; + } + + if( loadColor ) { + final ShaderCode vp = ShaderCode.create( gl, GL2ES2.GL_VERTEX_SHADER, shaderRootClass, shaderSrcRoot, + 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); + shaderProgramColor = new ShaderProgram(); + shaderProgramColor.add(vp); + shaderProgramColor.add(fp); + if(!shaderProgramColor.link(gl, System.err)) { + throw new GLException("Couldn't link VertexColor program: "+shaderProgramColor); + } + } else if( loadColorTexture ) { + final ShaderCode vp = ShaderCode.create( gl, GL2ES2.GL_VERTEX_SHADER, shaderRootClass, shaderSrcRoot, shaderBinRoot, vertexColorFile, true); + final ShaderCode fp = ShaderCode.create( gl, GL2ES2.GL_FRAGMENT_SHADER, shaderRootClass, shaderSrcRoot, + shaderBinRoot, fragmentColorTextureFile, true); + + if( loadColorTexture2 ) { + vp.insertShaderSource(0, 0, constMaxShader2); + fp.insertShaderSource(0, 0, constMaxShader2); + shaderProgramColorTexture2 = new ShaderProgram(); + shaderProgramColorTexture2.add(vp); + shaderProgramColorTexture2.add(fp); + if(!shaderProgramColorTexture2.link(gl, System.err)) { + throw new GLException("Couldn't link VertexColorTexture2 program: "+shaderProgramColorTexture2); + } + } else if( loadColorTexture4 ) { + vp.insertShaderSource(0, 0, constMaxShader4); + fp.insertShaderSource(0, 0, constMaxShader4); + shaderProgramColorTexture4 = new ShaderProgram(); + shaderProgramColorTexture4.add(vp); + shaderProgramColorTexture4.add(fp); + if(!shaderProgramColorTexture4.link(gl, System.err)) { + throw new GLException("Couldn't link VertexColorTexture4 program: "+shaderProgramColorTexture4); + } + } else if( loadColorTexture8 ) { + vp.insertShaderSource(0, 0, constMaxShader8); + fp.insertShaderSource(0, 0, constMaxShader8); + shaderProgramColorTexture8 = new ShaderProgram(); + shaderProgramColorTexture8.add(vp); + shaderProgramColorTexture8.add(fp); + if(!shaderProgramColorTexture8.link(gl, System.err)) { + throw new GLException("Couldn't link VertexColorTexture8 program: "+shaderProgramColorTexture8); + } + } + } else if( loadColorLightPerVertex ) { + final ShaderCode vp = ShaderCode.create( gl, GL2ES2.GL_VERTEX_SHADER, shaderRootClass, shaderSrcRoot, + 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); + shaderProgramColorLight = new ShaderProgram(); + shaderProgramColorLight.add(vp); + shaderProgramColorLight.add(fp); + if(!shaderProgramColorLight.link(gl, System.err)) { + throw new GLException("Couldn't link VertexColorLight program: "+shaderProgramColorLight); + } + } else if( loadColorTexture8LightPerVertex ) { + final ShaderCode vp = ShaderCode.create( gl, GL2ES2.GL_VERTEX_SHADER, shaderRootClass, shaderSrcRoot, + 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); + shaderProgramColorTexture8Light = new ShaderProgram(); + shaderProgramColorTexture8Light.add(vp); + shaderProgramColorTexture8Light.add(fp); + if(!shaderProgramColorTexture8Light.link(gl, System.err)) { + throw new GLException("Couldn't link VertexColorLight program: "+shaderProgramColorTexture8Light); + } + } + } + private ShaderProgram selectShaderProgram(GL2ES2 gl, ShaderSelectionMode mode) { + if(ShaderSelectionMode.AUTO == mode) { + mode = ShaderSelectionMode.COLOR; + } + loadShader(gl, mode); final ShaderProgram sp; switch(mode) { case COLOR_LIGHT_PER_VERTEX: sp = shaderProgramColorLight; break; - case COLOR_TEXTURE: - sp = shaderProgramColorTexture; + case COLOR_TEXTURE2: + sp = shaderProgramColorTexture2; + break; + case COLOR_TEXTURE4: + sp = shaderProgramColorTexture4; + break; + case COLOR_TEXTURE8: + sp = shaderProgramColorTexture8; break; - case COLOR_TEXTURE_LIGHT_PER_VERTEX: - sp = shaderProgramColorTextureLight; + case COLOR_TEXTURE8_LIGHT_PER_VERTEX: + sp = shaderProgramColorTexture8Light; break; - case AUTO: case COLOR: default: sp = shaderProgramColor; @@ -715,12 +852,7 @@ public class FixedFuncPipeline { return sp; } - private void init(GL2ES2 gl, ShaderSelectionMode mode, PMVMatrix pmvMatrix, Class shaderRootClass, String shaderSrcRoot, - String shaderBinRoot, - String vertexColorFile, - String vertexColorLightFile, - String fragmentColorFile, String fragmentColorTextureFile) - { + private void init(GL2ES2 gl, ShaderSelectionMode mode, PMVMatrix pmvMatrix) { if(null==pmvMatrix) { throw new GLException("PMVMatrix is null"); } @@ -728,47 +860,6 @@ public class FixedFuncPipeline { this.shaderSelectionMode = mode; this.shaderState=new ShaderState(); this.shaderState.setVerbose(verbose); - ShaderCode vertexColor, vertexColorLight, fragmentColor, fragmentColorTexture; - - vertexColor = ShaderCode.create( gl, GL2ES2.GL_VERTEX_SHADER, shaderRootClass, shaderSrcRoot, - shaderBinRoot, vertexColorFile, false); - - vertexColorLight = ShaderCode.create( gl, GL2ES2.GL_VERTEX_SHADER, shaderRootClass, shaderSrcRoot, - shaderBinRoot, vertexColorLightFile, false); - - fragmentColor = ShaderCode.create( gl, GL2ES2.GL_FRAGMENT_SHADER, shaderRootClass, shaderSrcRoot, - shaderBinRoot, fragmentColorFile, false); - - fragmentColorTexture = ShaderCode.create( gl, GL2ES2.GL_FRAGMENT_SHADER, shaderRootClass, shaderSrcRoot, - shaderBinRoot, fragmentColorTextureFile, false); - - shaderProgramColor = new ShaderProgram(); - shaderProgramColor.add(vertexColor); - shaderProgramColor.add(fragmentColor); - if(!shaderProgramColor.link(gl, System.err)) { - throw new GLException("Couldn't link VertexColor program: "+shaderProgramColor); - } - - shaderProgramColorTexture = new ShaderProgram(); - shaderProgramColorTexture.add(vertexColor); - shaderProgramColorTexture.add(fragmentColorTexture); - if(!shaderProgramColorTexture.link(gl, System.err)) { - throw new GLException("Couldn't link VertexColorTexture program: "+shaderProgramColorTexture); - } - - shaderProgramColorLight = new ShaderProgram(); - shaderProgramColorLight.add(vertexColorLight); - shaderProgramColorLight.add(fragmentColor); - if(!shaderProgramColorLight.link(gl, System.err)) { - throw new GLException("Couldn't link VertexColorLight program: "+shaderProgramColorLight); - } - - shaderProgramColorTextureLight = new ShaderProgram(); - shaderProgramColorTextureLight.add(vertexColorLight); - shaderProgramColorTextureLight.add(fragmentColorTexture); - if(!shaderProgramColorTextureLight.link(gl, System.err)) { - throw new GLException("Couldn't link VertexColorLight program: "+shaderProgramColorTextureLight); - } shaderState.attachShaderProgram(gl, selectShaderProgram(gl, shaderSelectionMode), true); @@ -854,9 +945,9 @@ public class FixedFuncPipeline { private PMVMatrix pmvMatrix; private ShaderState shaderState; private ShaderProgram shaderProgramColor; - private ShaderProgram shaderProgramColorTexture; + private ShaderProgram shaderProgramColorTexture2, shaderProgramColorTexture4, shaderProgramColorTexture8; private ShaderProgram shaderProgramColorLight; - private ShaderProgram shaderProgramColorTextureLight; + private ShaderProgram shaderProgramColorTexture8Light; private ShaderSelectionMode shaderSelectionMode = ShaderSelectionMode.AUTO; @@ -904,11 +995,19 @@ public class FixedFuncPipeline { public static final FloatBuffer defMatEmission = neut4f; public static final float defMatShininess = 0f; - private static final String vertexColorFileDef = "FixedFuncColor"; - private static final String vertexColorLightFileDef = "FixedFuncColorLight"; - private static final String fragmentColorFileDef = "FixedFuncColor"; - private static final String fragmentColorTextureFileDef = "FixedFuncColorTexture"; - private static final String shaderSrcRootDef = "shaders" ; - private static final String shaderBinRootDef = "shaders/bin" ; + private static final String vertexColorFileDef = "FixedFuncColor"; + private static final String vertexColorLightFileDef = "FixedFuncColorLight"; + private static final String fragmentColorFileDef = "FixedFuncColor"; + private static final String fragmentColorTextureFileDef = "FixedFuncColorTexture"; + private static final String shaderSrcRootDef = "shaders" ; + private static final String shaderBinRootDef = "shaders/bin" ; + + private final Class shaderRootClass; + private final String shaderSrcRoot; + private final String shaderBinRoot; + private final String vertexColorFile; + private final String vertexColorLightFile; + private final String fragmentColorFile; + private final String fragmentColorTextureFile; } 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 From e658ab1e427a7957b9dbfa4a396506de6c6582fd Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 14 Oct 2012 09:59:22 +0200 Subject: FixedFuncPipeline: Use ES2/GL2 prelude and set default precision. Shader code: Remove precision for default precision types. --- .../util/glsl/fixedfunc/FixedFuncPipeline.java | 44 ++++++++++++++-------- .../util/glsl/fixedfunc/shaders/FixedFuncColor.fp | 2 +- .../fixedfunc/shaders/FixedFuncColorTexture.fp | 10 ++--- .../util/glsl/fixedfunc/shaders/mgl_attribute.glsl | 22 +++++------ .../util/glsl/fixedfunc/shaders/mgl_const.glsl | 2 +- .../util/glsl/fixedfunc/shaders/mgl_uniform.glsl | 6 +-- 6 files changed, 49 insertions(+), 37 deletions(-) (limited to 'src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders') 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]; -- cgit v1.2.3 From f8fb65c7cd79743a6501fe63ff1e28479ceedb4f Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 15 Oct 2012 16:35:43 +0200 Subject: FixedFuncColorTexture.fp: Remove unused local var --- .../jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColorTexture.fp | 2 -- 1 file changed, 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 2593dc750..1810891b3 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 @@ -59,8 +59,6 @@ void main (void) ( MGL_FRONT_AND_BACK == mgl_CullFace ) ) ) { DISCARD(color); } 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]); -- cgit v1.2.3 From 1aea29bb5d253600213024fd2c12a91bf3599202 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 18 Oct 2012 16:50:40 +0200 Subject: FixedFuncPipeline: Don't handle CullFace, ES2 impl. already takes care of discarding pixels of culled faces. --- .../jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java | 4 +++- .../opengl/util/glsl/fixedfunc/FixedFuncPipeline.java | 15 ++++++++++----- .../opengl/util/glsl/fixedfunc/shaders/FixedFuncColor.fp | 3 ++- .../util/glsl/fixedfunc/shaders/FixedFuncColorTexture.fp | 7 ++++--- .../opengl/util/glsl/fixedfunc/shaders/mgl_uniform.glsl | 2 +- 5 files changed, 20 insertions(+), 11 deletions(-) (limited to 'src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders') diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java index ee2a08d1f..fad81226d 100644 --- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java @@ -341,10 +341,12 @@ public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFun public void glAlphaFunc(int func, float ref) { fixedFunction.glAlphaFunc(func, ref); } + + /** ES2 supports CullFace implicit public void glCullFace(int faceName) { fixedFunction.glCullFace(faceName); gl.glCullFace(faceName); - } + } */ // // PointerIf 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 f92c02403..72d105a44 100644 --- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncPipeline.java +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncPipeline.java @@ -447,6 +447,7 @@ public class FixedFuncPipeline { } } + /** ES2 supports CullFace implicit public void glCullFace(int faceName) { int _cullFace; switch(faceName) { @@ -471,7 +472,7 @@ public class FixedFuncPipeline { cullFaceDirty=true; } } - } + } */ public void glAlphaFunc(int func, float ref) { int _func; @@ -533,6 +534,7 @@ public class FixedFuncPipeline { return true; case GL.GL_CULL_FACE: + /** ES2 supports CullFace implicit final int _cullFace; if(0>cullFace && enable || 0 0 && ( ( MGL_FRONT == mgl_CullFace && gl_FrontFacing ) || ( MGL_BACK == mgl_CullFace && !gl_FrontFacing ) || ( MGL_FRONT_AND_BACK == mgl_CullFace ) ) ) { DISCARD(color); - } + } */ if( mgl_AlphaTestFunc > 0 ) { alphaTest(color); } 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 1810891b3..9a7e5217b 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 @@ -53,12 +53,13 @@ void main (void) { vec4 color = frontColor; + /** ES2 supports CullFace implicit .. if( mgl_CullFace > 0 && ( ( MGL_FRONT == mgl_CullFace && gl_FrontFacing ) || ( MGL_BACK == mgl_CullFace && !gl_FrontFacing ) || ( MGL_FRONT_AND_BACK == mgl_CullFace ) ) ) { DISCARD(color); - } else { + } else { */ #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]); @@ -90,9 +91,9 @@ void main (void) } #endif if( mgl_AlphaTestFunc > 0 ) { - alphaTest(color); + alphaTest(color); } - } + // } /* CullFace */ gl_FragColor = color; /** 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 b92037ef9..68245a62c 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,6 +11,7 @@ uniform LOWP int mgl_ColorEnabled; uniform vec4 mgl_ColorStatic; uniform LOWP int mgl_AlphaTestFunc; uniform float mgl_AlphaTestRef; +// uniform LOWP int mgl_CullFace; // ES2 supports CullFace implicit .. #if MAX_TEXTURE_UNITS > 0 uniform LOWP int mgl_TextureEnabled[MAX_TEXTURE_UNITS]; uniform LOWP int mgl_TexCoordEnabled[MAX_TEXTURE_UNITS]; @@ -31,6 +32,5 @@ uniform sampler2D mgl_Texture6; uniform sampler2D mgl_Texture7; #endif #endif -uniform LOWP int mgl_CullFace; #endif // mgl_uniform_glsl -- cgit v1.2.3 From 545a9422324f5c8ef47b48a2e3e5419c56f19f14 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 19 Oct 2012 18:08:40 +0200 Subject: FixedFuncPipeline: Add GL_POINT* state tracking; Fix glDrawArrays(): Issued twice (duh!) almost halfed performance :) TODO: Create GL_POINT texture and render w/ glDraw*() --- .../opengl/util/glsl/fixedfunc/FixedFuncHook.java | 63 +++-------- .../util/glsl/fixedfunc/FixedFuncPipeline.java | 115 +++++++++++++++++++++ .../util/glsl/fixedfunc/shaders/mgl_uniform.glsl | 2 + 3 files changed, 131 insertions(+), 49 deletions(-) (limited to 'src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders') diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java index fad81226d..43abfe5ef 100644 --- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java @@ -117,57 +117,13 @@ public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFun // FixedFuncHookIf - hooks // public void glDrawArrays(int mode, int first, int count) { - fixedFunction.validate(gl); - switch(mode) { - case GL2.GL_QUAD_STRIP: - mode=GL.GL_TRIANGLE_STRIP; - break; - case GL2.GL_POLYGON: - mode=GL.GL_TRIANGLE_FAN; - break; - } - if ( GL2.GL_QUADS == mode && !gl.isGL2() ) { - for (int j = first; j < count - 3; j += 4) { - gl.glDrawArrays(GL.GL_TRIANGLE_FAN, j, 4); - } - } else { - gl.glDrawArrays(mode, first, count); - } - - gl.glDrawArrays(mode, first, count); + fixedFunction.glDrawArrays(gl, mode, first, count); } public void glDrawElements(int mode, int count, int type, java.nio.Buffer indices) { - fixedFunction.validate(gl); - if ( GL2.GL_QUADS == mode && !gl.isGL2() ) { - final int idx0 = indices.position(); - - if( GL.GL_UNSIGNED_BYTE == type ) { - final ByteBuffer b = (ByteBuffer) indices; - for (int j = 0; j < count; j++) { - gl.glDrawArrays(GL.GL_TRIANGLE_FAN, (int)(0x000000ff & b.get(idx0+j)), 4); - } - } else if( GL.GL_UNSIGNED_SHORT == type ){ - final ShortBuffer b = (ShortBuffer) indices; - for (int j = 0; j < count; j++) { - gl.glDrawArrays(GL.GL_TRIANGLE_FAN, (int)(0x0000ffff & b.get(idx0+j)), 4); - } - } else { - final IntBuffer b = (IntBuffer) indices; - for (int j = 0; j < count; j++) { - gl.glDrawArrays(GL.GL_TRIANGLE_FAN, (int)(0xffffffff & b.get(idx0+j)), 4); - } - } - } else { - gl.glDrawElements(mode, count, type, indices); - // GL2: gl.glDrawRangeElements(mode, 0, count-1, count, type, indices); - } + fixedFunction.glDrawElements(gl, mode, count, type, indices); } public void glDrawElements(int mode, int count, int type, long indices_buffer_offset) { - fixedFunction.validate(gl); - if ( GL2.GL_QUADS == mode && !gl.isGL2() ) { - throw new GLException("Cannot handle indexed QUADS on !GL2 w/ VBO due to lack of CPU index access"); - } - gl.glDrawElements(mode, count, type, indices_buffer_offset); + fixedFunction.glDrawElements(gl, mode, count, type, indices_buffer_offset); } public void glActiveTexture(int texture) { @@ -247,8 +203,17 @@ public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFun gl.glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels_buffer_offset); } - public void glPointSize(float arg0) { - // NOP - FIXME ? + public void glPointSize(float size) { + fixedFunction.glPointSize(size); + } + public void glPointParameterf(int pname, float param) { + fixedFunction.glPointParameterf(pname, param); + } + public void glPointParameterfv(int pname, float[] params, int params_offset) { + fixedFunction.glPointParameterfv(pname, params, params_offset); + } + public void glPointParameterfv(int pname, java.nio.FloatBuffer params) { + fixedFunction.glPointParameterfv(pname, params); } // 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 72d105a44..0a3ec4a69 100644 --- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncPipeline.java +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncPipeline.java @@ -29,10 +29,13 @@ package jogamp.opengl.util.glsl.fixedfunc; +import java.nio.ByteBuffer; import java.nio.FloatBuffer; import java.nio.IntBuffer; +import java.nio.ShortBuffer; import javax.media.opengl.GL; +import javax.media.opengl.GL2; import javax.media.opengl.GL2ES1; import javax.media.opengl.GL2ES2; import javax.media.opengl.GLArrayData; @@ -332,6 +335,42 @@ public class FixedFuncPipeline { System.err.println("FixedFuncPipeline: Unimplemented glGetTexEnviv: target "+toHexString(target)+", pname "+toHexString(pname)); } + // + // Point Sprites + // + public void glPointSize(float size) { + pointParams.put(0, size); + } + public void glPointParameterf(int pname, float param) { + switch(pname) { + case GL2ES1.GL_POINT_SIZE_MIN: + pointParams.put(2, param); + break; + case GL2ES1.GL_POINT_SIZE_MAX: + pointParams.put(3, param); + break; + } + } + public void glPointParameterfv(int pname, float[] params, int params_offset) { + switch(pname) { + case GL2ES1.GL_POINT_DISTANCE_ATTENUATION: + pointParams.put(4, params[params_offset + 0]); + pointParams.put(5, params[params_offset + 1]); + pointParams.put(6, params[params_offset + 2]); + break; + } + } + public void glPointParameterfv(int pname, java.nio.FloatBuffer params) { + final int o = params.position(); + switch(pname) { + case GL2ES1.GL_POINT_DISTANCE_ATTENUATION: + pointParams.put(4, params.get(o + 0)); + pointParams.put(5, params.get(o + 1)); + pointParams.put(6, params.get(o + 2)); + break; + } + } + // // Lighting // @@ -577,6 +616,10 @@ public class FixedFuncPipeline { alphaTestFunc=_alphaTestFunc; } return false; + + case GL2ES1.GL_POINT_SMOOTH: + pointParams.put(1, enable ? 1.0f : 0.0f); + return false; } int light = cap - GLLightingFunc.GL_LIGHT0; @@ -591,6 +634,71 @@ public class FixedFuncPipeline { return false; // ignore! } + // + // Draw + // + + public void glDrawArrays(GL2ES2 gl, int mode, int first, int count) { + validate(gl); + switch(mode) { + case GL2.GL_QUAD_STRIP: + mode=GL.GL_TRIANGLE_STRIP; + break; + case GL2.GL_POLYGON: + mode=GL.GL_TRIANGLE_FAN; + break; + } + if ( GL2.GL_QUADS == mode && !gl.isGL2() ) { + for (int j = first; j < count - 3; j += 4) { + gl.glDrawArrays(GL.GL_TRIANGLE_FAN, j, 4); + } + } else if( GL2ES1.GL_POINTS != mode ) { + gl.glDrawArrays(mode, first, count); + } else { + // FIXME GL_POINTS ! + gl.glDrawArrays(mode, first, count); + } + } + public void glDrawElements(GL2ES2 gl, int mode, int count, int type, java.nio.Buffer indices) { + validate(gl); + if ( GL2.GL_QUADS == mode && !gl.isGL2() ) { + final int idx0 = indices.position(); + + if( GL.GL_UNSIGNED_BYTE == type ) { + final ByteBuffer b = (ByteBuffer) indices; + for (int j = 0; j < count; j++) { + gl.glDrawArrays(GL.GL_TRIANGLE_FAN, (int)(0x000000ff & b.get(idx0+j)), 4); + } + } else if( GL.GL_UNSIGNED_SHORT == type ){ + final ShortBuffer b = (ShortBuffer) indices; + for (int j = 0; j < count; j++) { + gl.glDrawArrays(GL.GL_TRIANGLE_FAN, (int)(0x0000ffff & b.get(idx0+j)), 4); + } + } else { + final IntBuffer b = (IntBuffer) indices; + for (int j = 0; j < count; j++) { + gl.glDrawArrays(GL.GL_TRIANGLE_FAN, (int)(0xffffffff & b.get(idx0+j)), 4); + } + } + } else if( GL2ES1.GL_POINTS != mode ) { + gl.glDrawElements(mode, count, type, indices); + } else { + // FIXME GL_POINTS ! + gl.glDrawElements(mode, count, type, indices); + } + } + public void glDrawElements(GL2ES2 gl, int mode, int count, int type, long indices_buffer_offset) { + validate(gl); + if ( GL2.GL_QUADS == mode && !gl.isGL2() ) { + throw new GLException("Cannot handle indexed QUADS on !GL2 w/ VBO due to lack of CPU index access"); + } else if( GL2ES1.GL_POINTS != mode ) { + // FIXME GL_POINTS ! + gl.glDrawElements(mode, count, type, indices_buffer_offset); + } else { + gl.glDrawElements(mode, count, type, indices_buffer_offset); + } + } + private final int textureEnabledCount() { int n=0; for(int i=MAX_TEXTURE_UNITS-1; i>=0; i--) { @@ -995,6 +1103,12 @@ public class FixedFuncPipeline { private boolean alphaTestDirty=false; private int alphaTestFunc=-8; // <=0 disabled; 1 GL_NEVER, 2 GL_LESS, 3 GL_EQUAL, 4 GL_LEQUAL, 5 GL_GREATER, 6 GL_NOTEQUAL, 7 GL_GEQUAL, and 8 GL_ALWAYS (default) private float alphaTestRef=0f; + + // pointSize, pointSmooth, attn. pointMinSize, attn. pointMaxSize + // attenuation coefficients 1f 0f 0f + // attenuation alpha theshold 1f + private final FloatBuffer pointParams = Buffers.newDirectFloatBuffer(new float[] { 1.0f, 0.0f, 0.0f, 1.0f, + 1.0f, 0.0f, 0.0f, 1.0f }); private PMVMatrix pmvMatrix; private ShaderState shaderState; @@ -1019,6 +1133,7 @@ public class FixedFuncPipeline { private static final String mgl_AlphaTestFunc = "mgl_AlphaTestFunc"; // 1i (lowp int) private static final String mgl_AlphaTestRef = "mgl_AlphaTestRef"; // 1f private static final String mgl_ShadeModel = "mgl_ShadeModel"; // 1i + private static final String mgl_PointParams = "mgl_PointParams"; // 8f (sz, smooth, attnMinSz, attnMaxSz, attnCoeff(3), attnAlphaTs) private static final String mgl_TextureEnabled = "mgl_TextureEnabled"; // int mgl_TextureEnabled[MAX_TEXTURE_UNITS]; private static final String mgl_Texture = "mgl_Texture"; // sampler2D mgl_Texture<0..7> 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 68245a62c..679583cd7 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,6 +11,8 @@ uniform LOWP int mgl_ColorEnabled; uniform vec4 mgl_ColorStatic; uniform LOWP int mgl_AlphaTestFunc; uniform float mgl_AlphaTestRef; +uniform float mgl_PointParams[8]; // sz, smooth, attnMinSz, attnMaxSz, attnCoeff(3), attnAlphaTs + // uniform LOWP int mgl_CullFace; // ES2 supports CullFace implicit .. #if MAX_TEXTURE_UNITS > 0 uniform LOWP int mgl_TextureEnabled[MAX_TEXTURE_UNITS]; -- cgit v1.2.3 From 9ad687e18a67d335ea8ed4868025d0c740e02583 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sat, 20 Oct 2012 10:51:57 +0200 Subject: FFP-Emu: Adding simple POINTS shader ; Adding GLRunnable2 interface, allowing passing a GL action w/ custom argument and return value. Adding simple POINTS shader not regarding POINTS parameters and not using a texture (commented out). FIXME: Event thought it works using a texture and gl_PointCoord in frag shader, I don't see the point here (lol) if gl_PointSize must be 1.0 in vert shader .. otherwise nothing is seen on ES2.0. On Desktop POINTS are always shown as 1 pixel sized points! --- .../classes/javax/media/opengl/GLRunnable2.java | 44 ++++ .../util/glsl/fixedfunc/FixedFuncPipeline.java | 258 ++++++++++++++++----- .../util/glsl/fixedfunc/shaders/FixedFuncPoints.fp | 16 ++ .../util/glsl/fixedfunc/shaders/FixedFuncPoints.vp | 25 ++ .../util/glsl/fixedfunc/shaders/mgl_uniform.glsl | 3 +- 5 files changed, 285 insertions(+), 61 deletions(-) create mode 100644 src/jogl/classes/javax/media/opengl/GLRunnable2.java create mode 100644 src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncPoints.fp create mode 100644 src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncPoints.vp (limited to 'src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders') diff --git a/src/jogl/classes/javax/media/opengl/GLRunnable2.java b/src/jogl/classes/javax/media/opengl/GLRunnable2.java new file mode 100644 index 000000000..1598a6215 --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/GLRunnable2.java @@ -0,0 +1,44 @@ +/** + * Copyright 2012 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 javax.media.opengl; + +/** + *

+ * Declares a one-shot OpenGL command. + *

+ */ +public interface GLRunnable2 { + /** + * @param gl a current GL object + * @param args custom arguments + * @return the desired object + */ + T run(GL gl, U args); +} + 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 0a3ec4a69..a5ab684b6 100644 --- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncPipeline.java +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncPipeline.java @@ -38,8 +38,10 @@ import javax.media.opengl.GL; import javax.media.opengl.GL2; import javax.media.opengl.GL2ES1; import javax.media.opengl.GL2ES2; +import javax.media.opengl.GL2GL3; import javax.media.opengl.GLArrayData; import javax.media.opengl.GLException; +import javax.media.opengl.GLRunnable2; import javax.media.opengl.GLUniformData; import javax.media.opengl.fixedfunc.GLLightingFunc; import javax.media.opengl.fixedfunc.GLPointerFunc; @@ -213,6 +215,22 @@ public class FixedFuncPipeline { // MULTI-TEXTURE // + /** Enables/Disables the named texture unit (if changed), returns previous state */ + private boolean glEnableTexture(boolean enable, int unit) { + final boolean isEnabled = 0 != ( textureEnabledBits & ( 1 << activeTextureUnit ) ); + if( isEnabled != enable ) { + if(enable) { + textureEnabledBits |= ( 1 << unit ); + textureEnabled.put(unit, 1); + } else { + textureEnabledBits &= ~( 1 << unit ); + textureEnabled.put(unit, 0); + } + textureEnabledDirty=true; + } + return isEnabled; + } + public void glClientActiveTexture(int textureUnit) { textureUnit -= GL.GL_TEXTURE0; if(0 <= textureUnit && textureUnit glDrawAction, Object args) { + /** + * FIXME: + * + * Event thought it works using a texture and gl_PointCoord in frag shader, + * I don't see the point here (lol) if gl_PointSize must be 1.0 in vert shader .. + * otherwise nothing is seen on ES2.0. + * On Desktop POINTS are always shown as 1 pixel sized points! + + final int prevActiveTextureUnit = activeTextureUnit; + final int prevBoundTextureObject = this.boundTextureObject[0]; + glActiveTexture(GL.GL_TEXTURE0); + gl.glActiveTexture(GL.GL_TEXTURE0); + if( 0 == pointTexObj[0] ) { + gl.glGenTextures(1, pointTexObj, 0); + glBindTexture(GL.GL_TEXTURE_2D, pointTexObj[0]); + gl.glBindTexture(GL.GL_TEXTURE_2D, pointTexObj[0]); + final int sz = 32; + ByteBuffer bb = Buffers.newDirectByteBuffer(sz*sz*4); + for(int i=sz*sz*4-1; 0<=i; i--) { + bb.put(i, (byte)0xff); + } + glTexImage2D(GL.GL_TEXTURE_2D, GL.GL_RGBA, GL.GL_RGBA); + gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, sz, sz, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, bb); + gl.glTexParameteri ( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR ); + gl.glTexParameteri ( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR ); + gl.glTexParameteri ( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT ); + gl.glTexParameteri ( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT ); + } else { + glBindTexture(GL.GL_TEXTURE_2D, pointTexObj[0]); + gl.glBindTexture(GL.GL_TEXTURE_2D, pointTexObj[0]); + } + final boolean wasEnabled = glEnableTexture(true, 0); + */ + + loadShaderPoints(gl); + shaderState.attachShaderProgram(gl, shaderProgramPoints, true); + validate(gl, false); // sync uniforms + if(gl.isGL2GL3()) { + // if(gl.isGL2()) { + // gl.glEnable(GL2.GL_POINT_SPRITE); + //} + gl.glEnable(GL2GL3.GL_VERTEX_PROGRAM_POINT_SIZE); + } + + glDrawAction.run(gl, args); + + if(gl.isGL2GL3()) { + gl.glDisable(GL2GL3.GL_VERTEX_PROGRAM_POINT_SIZE); + // if(gl.isGL2()) { + // gl.glDisable(GL2.GL_POINT_SPRITE); + //} + } + /** + if( 0 != prevBoundTextureObject ) { + glBindTexture(GL.GL_TEXTURE_2D, prevBoundTextureObject); + gl.glBindTexture(GL.GL_TEXTURE_2D, prevBoundTextureObject); + } + glActiveTexture(GL.GL_TEXTURE0+prevActiveTextureUnit); + gl.glActiveTexture(GL.GL_TEXTURE0+prevActiveTextureUnit); + if(!wasEnabled) { + glEnableTexture(false, 0); + } */ + shaderState.attachShaderProgram(gl, selectShaderProgram(gl, currentShaderSelectionMode), true); + } + private static final GLRunnable2 glDrawArraysAction = new GLRunnable2() { + @Override + public Object run(GL gl, Object args) { + int[] _args = (int[])args; + gl.glDrawArrays(GL.GL_POINTS, _args[0], _args[1]); + return null; + } + }; + private final void glDrawPointArrays(GL2ES2 gl, int first, int count) { + glDrawPoints(gl, glDrawArraysAction, new int[] { first, count }); + } + // // Lighting // @@ -554,7 +658,7 @@ public class FixedFuncPipeline { } } } - + /** * @return false if digested in regard to GL2ES2 spec, * eg this call must not be passed to an underlying ES2 implementation. @@ -587,17 +691,7 @@ public class FixedFuncPipeline { return true; case GL.GL_TEXTURE_2D: - final boolean isEnabled = 0 != ( textureEnabledBits & ( 1 << activeTextureUnit ) ); - if( isEnabled != enable ) { - if(enable) { - textureEnabledBits |= ( 1 << activeTextureUnit ); - textureEnabled.put(activeTextureUnit, 1); - } else { - textureEnabledBits &= ~( 1 << activeTextureUnit ); - textureEnabled.put(activeTextureUnit, 0); - } - textureEnabledDirty=true; - } + glEnableTexture(enable, activeTextureUnit); return false; case GLLightingFunc.GL_LIGHTING: @@ -618,7 +712,8 @@ public class FixedFuncPipeline { return false; case GL2ES1.GL_POINT_SMOOTH: - pointParams.put(1, enable ? 1.0f : 0.0f); + pointParams1.put(1, enable ? 1.0f : 0.0f); + pointParamsDirty = true; return false; } @@ -639,7 +734,6 @@ public class FixedFuncPipeline { // public void glDrawArrays(GL2ES2 gl, int mode, int first, int count) { - validate(gl); switch(mode) { case GL2.GL_QUAD_STRIP: mode=GL.GL_TRIANGLE_STRIP; @@ -647,20 +741,21 @@ public class FixedFuncPipeline { case GL2.GL_POLYGON: mode=GL.GL_TRIANGLE_FAN; break; + case GL2ES1.GL_POINTS: + glDrawPointArrays(gl, first, count); + return; } + validate(gl, true); if ( GL2.GL_QUADS == mode && !gl.isGL2() ) { for (int j = first; j < count - 3; j += 4) { gl.glDrawArrays(GL.GL_TRIANGLE_FAN, j, 4); } - } else if( GL2ES1.GL_POINTS != mode ) { + } else { gl.glDrawArrays(mode, first, count); - } else { - // FIXME GL_POINTS ! - gl.glDrawArrays(mode, first, count); } } public void glDrawElements(GL2ES2 gl, int mode, int count, int type, java.nio.Buffer indices) { - validate(gl); + validate(gl, true); if ( GL2.GL_QUADS == mode && !gl.isGL2() ) { final int idx0 = indices.position(); @@ -688,7 +783,7 @@ public class FixedFuncPipeline { } } public void glDrawElements(GL2ES2 gl, int mode, int count, int type, long indices_buffer_offset) { - validate(gl); + validate(gl, true); if ( GL2.GL_QUADS == mode && !gl.isGL2() ) { throw new GLException("Cannot handle indexed QUADS on !GL2 w/ VBO due to lack of CPU index access"); } else if( GL2ES1.GL_POINTS != mode ) { @@ -709,34 +804,36 @@ public class FixedFuncPipeline { return n; } - public void validate(GL2ES2 gl) { - if( ShaderSelectionMode.AUTO == requestedShaderSelectionMode) { - final ShaderSelectionMode newMode; - - // pre-validate shader switch - if( 0 != textureEnabledBits ) { - if(lightingEnabled) { - newMode = ShaderSelectionMode.COLOR_TEXTURE8_LIGHT_PER_VERTEX; + public void validate(GL2ES2 gl, boolean selectShader) { + if( selectShader ) { + if( ShaderSelectionMode.AUTO == requestedShaderSelectionMode) { + final ShaderSelectionMode newMode; + + // pre-validate shader switch + if( 0 != textureEnabledBits ) { + if(lightingEnabled) { + newMode = ShaderSelectionMode.COLOR_TEXTURE8_LIGHT_PER_VERTEX; + } else { + final int n = textureEnabledCount(); + if( 4 < n ) { + newMode = ShaderSelectionMode.COLOR_TEXTURE8; + } else if ( 2 < n ) { + newMode = ShaderSelectionMode.COLOR_TEXTURE4; + } else { + newMode = ShaderSelectionMode.COLOR_TEXTURE2; + } + } } else { - final int n = textureEnabledCount(); - if( 4 < n ) { - newMode = ShaderSelectionMode.COLOR_TEXTURE8; - } else if ( 2 < n ) { - newMode = ShaderSelectionMode.COLOR_TEXTURE4; + if(lightingEnabled) { + newMode = ShaderSelectionMode.COLOR_LIGHT_PER_VERTEX; } else { - newMode = ShaderSelectionMode.COLOR_TEXTURE2; + newMode = ShaderSelectionMode.COLOR; } } + shaderState.attachShaderProgram(gl, selectShaderProgram(gl, newMode), true); // enables shader-program implicit } else { - if(lightingEnabled) { - newMode = ShaderSelectionMode.COLOR_LIGHT_PER_VERTEX; - } else { - newMode = ShaderSelectionMode.COLOR; - } + shaderState.useProgram(gl, true); } - shaderState.attachShaderProgram(gl, selectShaderProgram(gl, newMode), true); // enables shader-program implicit - } else { - shaderState.useProgram(gl, true); } GLUniformData ud; @@ -793,6 +890,21 @@ public class FixedFuncPipeline { } alphaTestDirty = false; } + if(pointParamsDirty) { + /** FIXME + ud = shaderState.getUniform(mgl_PointParams1); + if(null!=ud) { + // same data object + shaderState.uniform(gl, ud); + } + ud = shaderState.getUniform(mgl_PointParams2); + if(null!=ud) { + // same data object + shaderState.uniform(gl, ud); + } */ + pointParamsDirty = false; + } + if(lightsEnabledDirty) { ud = shaderState.getUniform(mgl_LightsEnabled); if(null!=ud) { @@ -872,7 +984,9 @@ public class FixedFuncPipeline { // 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"; + // static final String gl2_prelude = "#version 110\n"; // GL 2.0 + // static final String gl2_prelude = "#version 120\n"; // GL 2.1 (Nvidia driver claims it's required to use gl_Points -> driver bug) + 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"; @@ -891,6 +1005,24 @@ public class FixedFuncPipeline { vp.insertShaderSource(0, rsVpPos, maxTextureDefine); fp.insertShaderSource(0, rsFpPos, maxTextureDefine); } + + private void loadShaderPoints(GL2ES2 gl) { + if( null != shaderProgramPoints ) { + return; + } + + final ShaderCode vp = ShaderCode.create( gl, GL2ES2.GL_VERTEX_SHADER, shaderRootClass, shaderSrcRoot, + shaderBinRoot, vertexPointsFileDef, true); + final ShaderCode fp = ShaderCode.create( gl, GL2ES2.GL_FRAGMENT_SHADER, shaderRootClass, shaderSrcRoot, + shaderBinRoot, fragmentPointsFileDef, true); + customizeShader(gl, vp, fp, constMaxTextures2); + shaderProgramPoints = new ShaderProgram(); + shaderProgramPoints.add(vp); + shaderProgramPoints.add(fp); + if(!shaderProgramPoints.link(gl, System.err)) { + throw new GLException("Couldn't link VertexColor program: "+shaderProgramPoints); + } + } private void loadShader(GL2ES2 gl, ShaderSelectionMode mode) { final boolean loadColor = ShaderSelectionMode.COLOR == mode; @@ -900,7 +1032,7 @@ public class FixedFuncPipeline { final boolean loadColorTexture = loadColorTexture2 || loadColorTexture4 || loadColorTexture8 ; final boolean loadColorLightPerVertex = ShaderSelectionMode.COLOR_LIGHT_PER_VERTEX == mode; final boolean loadColorTexture8LightPerVertex = ShaderSelectionMode.COLOR_TEXTURE8_LIGHT_PER_VERTEX == mode; - + if( null != shaderProgramColor && loadColor || null != shaderProgramColorTexture2 && loadColorTexture2 || null != shaderProgramColorTexture4 && loadColorTexture4 || @@ -1040,7 +1172,9 @@ public class FixedFuncPipeline { /** ES2 supports CullFace implicit shaderState.uniform(gl, new GLUniformData(mgl_CullFace, cullFace)); */ shaderState.uniform(gl, new GLUniformData(mgl_AlphaTestFunc, alphaTestFunc)); - shaderState.uniform(gl, new GLUniformData(mgl_AlphaTestRef, alphaTestRef)); + shaderState.uniform(gl, new GLUniformData(mgl_AlphaTestRef, alphaTestRef)); + shaderState.uniform(gl, new GLUniformData(mgl_PointParams1, 4, pointParams1)); + shaderState.uniform(gl, new GLUniformData(mgl_PointParams2, 4, pointParams2)); for(int i=0; i @@ -1168,6 +1304,8 @@ public class FixedFuncPipeline { private static final String vertexColorLightFileDef = "FixedFuncColorLight"; private static final String fragmentColorFileDef = "FixedFuncColor"; private static final String fragmentColorTextureFileDef = "FixedFuncColorTexture"; + private static final String vertexPointsFileDef = "FixedFuncPoints"; + private static final String fragmentPointsFileDef = vertexPointsFileDef; private static final String shaderSrcRootDef = "shaders" ; private static final String shaderBinRootDef = "shaders/bin" ; 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 new file mode 100644 index 000000000..beca47bc1 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncPoints.fp @@ -0,0 +1,16 @@ + +#include es_precision.glsl +#include mgl_lightdef.glsl + +#include mgl_const.glsl +#include mgl_uniform.glsl +#include mgl_varying.glsl + +void main (void) +{ + // FIXME: Since gl_Points must be 1.0 (otherwise no points) + // don't see reason for fetching texture color. + // gl_FragColor = frontColor * texture2D(mgl_Texture0, gl_PointCoord); + gl_FragColor = frontColor; +} + 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 new file mode 100644 index 000000000..6d6a3a982 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncPoints.vp @@ -0,0 +1,25 @@ +#include es_precision.glsl + +#include mgl_const.glsl +#include mgl_uniform.glsl +#include mgl_attribute.glsl +#include mgl_varying.glsl + +#include mgl_settexcoord.vp + +void main(void) +{ + if(mgl_ColorEnabled>0) { + frontColor=mgl_Color; + } else { + frontColor=mgl_ColorStatic; + } + + // FIXME: ES2 .. doesn't work, but even on desktop + // no big points! + // gl_PointSize = mgl_PointParams1[0]; + gl_PointSize = 1.0; + + gl_Position = mgl_PMVMatrix[0] * mgl_PMVMatrix[1] * vec4(mgl_Vertex.xyz, 1.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 679583cd7..fd24a953d 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,7 +11,8 @@ uniform LOWP int mgl_ColorEnabled; uniform vec4 mgl_ColorStatic; uniform LOWP int mgl_AlphaTestFunc; uniform float mgl_AlphaTestRef; -uniform float mgl_PointParams[8]; // sz, smooth, attnMinSz, attnMaxSz, attnCoeff(3), attnAlphaTs +uniform MEDIUMP float mgl_PointParams1[4]; // sz, smooth, attnMinSz, attnMaxSz +uniform MEDIUMP float mgl_PointParams2[4]; // attnCoeff(3), attnAlphaTs // uniform LOWP int mgl_CullFace; // ES2 supports CullFace implicit .. #if MAX_TEXTURE_UNITS > 0 -- cgit v1.2.3 From 5bdd283a9c3d0c656c859d499476173e2f609839 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 22 Oct 2012 18:54:19 +0200 Subject: FixedFuncPipeline GL_POINTS: Fix gl_PointSize (attribute data format), Add GL_POINT_SOFT and dist/fade attenuation (Adding basic POINT unit tests) gl_PointSize (and all other uniform array elems) was not propagated due to wrong usage of GLUniformData component param. Due to efficiency, we use vec4[2] now and #defines in shader to easy readability. GL_POINT_SOFT uses gl_PointCoord to determnine inside/outside circle position while adding a seam of 10% in/out. This almost matches 'other' implementations and gives a nice smooth circle. !GL_POINT_SOFT produces a proper square (billboard). Point-Vertex shader takes dist/fade attentuation into account. --- make/scripts/tests.sh | 3 +- .../util/glsl/fixedfunc/FixedFuncPipeline.java | 119 ++++-------- .../util/glsl/fixedfunc/shaders/FixedFuncPoints.fp | 29 ++- .../util/glsl/fixedfunc/shaders/FixedFuncPoints.vp | 25 ++- .../util/glsl/fixedfunc/shaders/mgl_uniform.glsl | 15 +- .../test/junit/jogl/acore/TestPointsNEWT.java | 138 ++++++++++++++ .../opengl/test/junit/jogl/demos/PointsDemo.java | 48 +++++ .../test/junit/jogl/demos/es1/PointsDemoES1.java | 155 +++++++++++++++ .../test/junit/jogl/demos/es2/PointsDemoES2.java | 207 +++++++++++++++++++++ .../junit/jogl/demos/es2/shader/PointsShader.fp | 40 ++++ .../junit/jogl/demos/es2/shader/PointsShader.vp | 42 +++++ 11 files changed, 723 insertions(+), 98 deletions(-) create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/acore/TestPointsNEWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/demos/PointsDemo.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/PointsDemoES1.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/PointsDemoES2.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/PointsShader.fp create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/PointsShader.vp (limited to 'src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders') diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh index 85b439437..0d16ec002 100755 --- a/make/scripts/tests.sh +++ b/make/scripts/tests.sh @@ -245,7 +245,7 @@ function testawtswt() { #testnoawt com.jogamp.newt.opengl.GLWindow $* #testnoawt com.jogamp.opengl.test.junit.jogl.offscreen.TestOffscreen01GLPBufferNEWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.offscreen.TestOffscreen02BitmapNEWT $* -testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT $* +#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestElektronenMultipliziererNEWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestFloatUtil01MatrixMatrixMultNOUI $* #testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestPMVMatrix01NEWT $* @@ -265,6 +265,7 @@ testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestSharedContextVBOES2NEWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGLAutoDrawableDelegateNEWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGLContextDrawableSwitchNEWT $* +testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestPointsNEWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT $* #testawt com.jogamp.opengl.test.junit.jogl.acore.TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT $* 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 a5ab684b6..8e0091e4c 100644 --- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncPipeline.java +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncPipeline.java @@ -357,19 +357,19 @@ public class FixedFuncPipeline { // Point Sprites // public void glPointSize(float size) { - pointParams1.put(0, size); + pointParams.put(0, size); pointParamsDirty = true; } public void glPointParameterf(int pname, float param) { switch(pname) { case GL2ES1.GL_POINT_SIZE_MIN: - pointParams1.put(2, param); + pointParams.put(2, param); break; case GL2ES1.GL_POINT_SIZE_MAX: - pointParams1.put(3, param); + pointParams.put(3, param); break; case GL2ES2.GL_POINT_FADE_THRESHOLD_SIZE: - pointParams2.put(3, param); + pointParams.put(4+3, param); break; } pointParamsDirty = true; @@ -377,9 +377,9 @@ public class FixedFuncPipeline { public void glPointParameterfv(int pname, float[] params, int params_offset) { switch(pname) { case GL2ES1.GL_POINT_DISTANCE_ATTENUATION: - pointParams2.put(0, params[params_offset + 0]); - pointParams2.put(1, params[params_offset + 1]); - pointParams2.put(2, params[params_offset + 2]); + pointParams.put(4+0, params[params_offset + 0]); + pointParams.put(4+1, params[params_offset + 1]); + pointParams.put(4+2, params[params_offset + 2]); break; } pointParamsDirty = true; @@ -388,9 +388,9 @@ public class FixedFuncPipeline { final int o = params.position(); switch(pname) { case GL2ES1.GL_POINT_DISTANCE_ATTENUATION: - pointParams2.put(0, params.get(o + 0)); - pointParams2.put(1, params.get(o + 1)); - pointParams2.put(2, params.get(o + 2)); + pointParams.put(4+0, params.get(o + 0)); + pointParams.put(4+1, params.get(o + 1)); + pointParams.put(4+2, params.get(o + 2)); break; } pointParamsDirty = true; @@ -399,68 +399,24 @@ public class FixedFuncPipeline { // private int[] pointTexObj = new int[] { 0 }; private void glDrawPoints(GL2ES2 gl, GLRunnable2 glDrawAction, Object args) { - /** - * FIXME: - * - * Event thought it works using a texture and gl_PointCoord in frag shader, - * I don't see the point here (lol) if gl_PointSize must be 1.0 in vert shader .. - * otherwise nothing is seen on ES2.0. - * On Desktop POINTS are always shown as 1 pixel sized points! - - final int prevActiveTextureUnit = activeTextureUnit; - final int prevBoundTextureObject = this.boundTextureObject[0]; - glActiveTexture(GL.GL_TEXTURE0); - gl.glActiveTexture(GL.GL_TEXTURE0); - if( 0 == pointTexObj[0] ) { - gl.glGenTextures(1, pointTexObj, 0); - glBindTexture(GL.GL_TEXTURE_2D, pointTexObj[0]); - gl.glBindTexture(GL.GL_TEXTURE_2D, pointTexObj[0]); - final int sz = 32; - ByteBuffer bb = Buffers.newDirectByteBuffer(sz*sz*4); - for(int i=sz*sz*4-1; 0<=i; i--) { - bb.put(i, (byte)0xff); - } - glTexImage2D(GL.GL_TEXTURE_2D, GL.GL_RGBA, GL.GL_RGBA); - gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, sz, sz, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, bb); - gl.glTexParameteri ( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR ); - gl.glTexParameteri ( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR ); - gl.glTexParameteri ( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT ); - gl.glTexParameteri ( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT ); - } else { - glBindTexture(GL.GL_TEXTURE_2D, pointTexObj[0]); - gl.glBindTexture(GL.GL_TEXTURE_2D, pointTexObj[0]); + if(gl.isGL2GL3()) { + gl.glEnable(GL2GL3.GL_VERTEX_PROGRAM_POINT_SIZE); + } + if(gl.isGL2ES1()) { + gl.glEnable(GL2ES1.GL_POINT_SPRITE); } - final boolean wasEnabled = glEnableTexture(true, 0); - */ - loadShaderPoints(gl); shaderState.attachShaderProgram(gl, shaderProgramPoints, true); validate(gl, false); // sync uniforms - if(gl.isGL2GL3()) { - // if(gl.isGL2()) { - // gl.glEnable(GL2.GL_POINT_SPRITE); - //} - gl.glEnable(GL2GL3.GL_VERTEX_PROGRAM_POINT_SIZE); - } glDrawAction.run(gl, args); + if(gl.isGL2ES1()) { + gl.glDisable(GL2ES1.GL_POINT_SPRITE); + } if(gl.isGL2GL3()) { gl.glDisable(GL2GL3.GL_VERTEX_PROGRAM_POINT_SIZE); - // if(gl.isGL2()) { - // gl.glDisable(GL2.GL_POINT_SPRITE); - //} } - /** - if( 0 != prevBoundTextureObject ) { - glBindTexture(GL.GL_TEXTURE_2D, prevBoundTextureObject); - gl.glBindTexture(GL.GL_TEXTURE_2D, prevBoundTextureObject); - } - glActiveTexture(GL.GL_TEXTURE0+prevActiveTextureUnit); - gl.glActiveTexture(GL.GL_TEXTURE0+prevActiveTextureUnit); - if(!wasEnabled) { - glEnableTexture(false, 0); - } */ shaderState.attachShaderProgram(gl, selectShaderProgram(gl, currentShaderSelectionMode), true); } private static final GLRunnable2 glDrawArraysAction = new GLRunnable2() { @@ -712,9 +668,13 @@ public class FixedFuncPipeline { return false; case GL2ES1.GL_POINT_SMOOTH: - pointParams1.put(1, enable ? 1.0f : 0.0f); + pointParams.put(1, enable ? 1.0f : 0.0f); pointParamsDirty = true; return false; + + case GL2ES1.GL_POINT_SPRITE: + // gl_PointCoord always enabled + return false; } int light = cap - GLLightingFunc.GL_LIGHT0; @@ -859,11 +819,13 @@ public class FixedFuncPipeline { if(colorVAEnabledDirty) { ud = shaderState.getUniform(mgl_ColorEnabled); if(null!=ud) { - int ca = (shaderState.isVertexAttribArrayEnabled(GLPointerFuncUtil.mgl_Color)==true)?1:0; + int ca = true == shaderState.isVertexAttribArrayEnabled(GLPointerFuncUtil.mgl_Color) ? 1 : 0 ; if(ca!=ud.intValue()) { ud.setData(ca); shaderState.uniform(gl, ud); } + } else { + throw new GLException("Failed to update: mgl_ColorEnabled"); } colorVAEnabledDirty = false; } @@ -891,17 +853,11 @@ public class FixedFuncPipeline { alphaTestDirty = false; } if(pointParamsDirty) { - /** FIXME - ud = shaderState.getUniform(mgl_PointParams1); + ud = shaderState.getUniform(mgl_PointParams); if(null!=ud) { // same data object shaderState.uniform(gl, ud); } - ud = shaderState.getUniform(mgl_PointParams2); - if(null!=ud) { - // same data object - shaderState.uniform(gl, ud); - } */ pointParamsDirty = false; } @@ -1012,9 +968,9 @@ public class FixedFuncPipeline { } final ShaderCode vp = ShaderCode.create( gl, GL2ES2.GL_VERTEX_SHADER, shaderRootClass, shaderSrcRoot, - shaderBinRoot, vertexPointsFileDef, true); + shaderBinRoot, shaderPointFileDef, true); final ShaderCode fp = ShaderCode.create( gl, GL2ES2.GL_FRAGMENT_SHADER, shaderRootClass, shaderSrcRoot, - shaderBinRoot, fragmentPointsFileDef, true); + shaderBinRoot, shaderPointFileDef, true); customizeShader(gl, vp, fp, constMaxTextures2); shaderProgramPoints = new ShaderProgram(); shaderProgramPoints.add(vp); @@ -1173,8 +1129,7 @@ public class FixedFuncPipeline { shaderState.uniform(gl, new GLUniformData(mgl_CullFace, cullFace)); */ shaderState.uniform(gl, new GLUniformData(mgl_AlphaTestFunc, alphaTestFunc)); shaderState.uniform(gl, new GLUniformData(mgl_AlphaTestRef, alphaTestRef)); - shaderState.uniform(gl, new GLUniformData(mgl_PointParams1, 4, pointParams1)); - shaderState.uniform(gl, new GLUniformData(mgl_PointParams2, 4, pointParams2)); + shaderState.uniform(gl, new GLUniformData(mgl_PointParams, 4, pointParams)); for(int i=0; i @@ -1304,8 +1256,7 @@ public class FixedFuncPipeline { private static final String vertexColorLightFileDef = "FixedFuncColorLight"; private static final String fragmentColorFileDef = "FixedFuncColor"; private static final String fragmentColorTextureFileDef = "FixedFuncColorTexture"; - private static final String vertexPointsFileDef = "FixedFuncPoints"; - private static final String fragmentPointsFileDef = vertexPointsFileDef; + private static final String shaderPointFileDef = "FixedFuncPoints"; private static final String shaderSrcRootDef = "shaders" ; private static final String shaderBinRootDef = "shaders/bin" ; 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 beca47bc1..6185e96ef 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 @@ -6,11 +6,34 @@ #include mgl_uniform.glsl #include mgl_varying.glsl +// #define TEST 1 + void main (void) { - // FIXME: Since gl_Points must be 1.0 (otherwise no points) - // don't see reason for fetching texture color. - // gl_FragColor = frontColor * texture2D(mgl_Texture0, gl_PointCoord); gl_FragColor = frontColor; + + if( pointSmooth > 0.5 ) { + // smooth (AA) + const float border = 0.90; // take/give 10% for AA + + // origin to 0/0, [-1/-1 .. 1/1] + vec2 pointPos = 2.0 * gl_PointCoord - 1.0 ; + float r = length( pointPos ); // one-circle sqrt(x * x + y * y), range: in-circle [0..1], out >1 + float r1 = 1.0 - ( step(border, r) * 10.0 * ( r - border ) ) ; // [0..1] + #ifndef TEST + if( r1 < 0.0 ) { + discard; + } + #endif + + #ifndef TEST + gl_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; + #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 6d6a3a982..64732dc9e 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 @@ -9,17 +9,26 @@ void main(void) { - if(mgl_ColorEnabled>0) { - frontColor=mgl_Color; + if( mgl_ColorEnabled > 0 ) { + frontColor = mgl_Color; } else { - frontColor=mgl_ColorStatic; + frontColor = mgl_ColorStatic; } - // FIXME: ES2 .. doesn't work, but even on desktop - // no big points! - // gl_PointSize = mgl_PointParams1[0]; - gl_PointSize = 1.0; + vec4 eyeCoord = mgl_PMVMatrix[1] * mgl_Vertex; + gl_Position = mgl_PMVMatrix[0] * eyeCoord; - gl_Position = mgl_PMVMatrix[0] * mgl_PMVMatrix[1] * vec4(mgl_Vertex.xyz, 1.0); + float dist = distance(eyeCoord, vec4(0.0, 0.0, 0.0, 1.0)); + float atten = sqrt( 1.0 / ( pointDistanceConstantAtten + + ( pointDistanceLinearAtten + + pointDistanceQuadraticAtten * dist + ) * dist + ) + ); + float size = clamp(pointSize * atten, pointSizeMin, pointSizeMax); + gl_PointSize = max(size, pointFadeThresholdSize); + + float fade = min(size, pointFadeThresholdSize) / pointFadeThresholdSize; + frontColor.a *= fade * fade; } 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 fd24a953d..5029e4bd8 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,8 +11,19 @@ uniform LOWP int mgl_ColorEnabled; uniform vec4 mgl_ColorStatic; uniform LOWP int mgl_AlphaTestFunc; uniform float mgl_AlphaTestRef; -uniform MEDIUMP float mgl_PointParams1[4]; // sz, smooth, attnMinSz, attnMaxSz -uniform MEDIUMP float mgl_PointParams2[4]; // attnCoeff(3), attnAlphaTs + +// [0].rgba: size, smooth, attnMinSz, attnMaxSz +// [1].rgba: attnCoeff(3), attnFadeTs +uniform MEDIUMP vec4 mgl_PointParams[2]; + +#define pointSize (mgl_PointParams[0].r) +#define pointSmooth (mgl_PointParams[0].g) +#define pointSizeMin (mgl_PointParams[0].b) +#define pointSizeMax (mgl_PointParams[0].a) +#define pointDistanceConstantAtten (mgl_PointParams[1].r) +#define pointDistanceLinearAtten (mgl_PointParams[1].g) +#define pointDistanceQuadraticAtten (mgl_PointParams[1].b) +#define pointFadeThresholdSize (mgl_PointParams[1].a) // uniform LOWP int mgl_CullFace; // ES2 supports CullFace implicit .. #if MAX_TEXTURE_UNITS > 0 diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestPointsNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestPointsNEWT.java new file mode 100644 index 000000000..37994914e --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestPointsNEWT.java @@ -0,0 +1,138 @@ +/** + * Copyright 2011 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.acore; + +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.test.junit.util.UITestCase; + +import com.jogamp.opengl.test.junit.jogl.demos.PointsDemo; +import com.jogamp.opengl.test.junit.jogl.demos.es1.PointsDemoES1; +import com.jogamp.opengl.test.junit.jogl.demos.es2.PointsDemoES2; + +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.AfterClass; +import org.junit.Test; + +public class TestPointsNEWT extends UITestCase { + static int width, height; + + @BeforeClass + public static void initClass() { + width = 512; + height = 512; + } + + @AfterClass + public static void releaseClass() { + } + + protected void runTestGL0(GLCapabilities caps, PointsDemo demo) throws InterruptedException { + GLWindow glWindow = GLWindow.create(caps); + Assert.assertNotNull(glWindow); + glWindow.setTitle(getSimpleTestName(".")); + + glWindow.addGLEventListener(demo); + final SnapshotGLEventListener snap = new SnapshotGLEventListener(); + snap.setPostSNDetail(demo.getClass().getSimpleName()); + glWindow.addGLEventListener(snap); + + glWindow.setSize(width, height); + glWindow.setVisible(true); + + demo.setSmoothPoints(false); + snap.setMakeSnapshot(); + snap.setPostSNDetail("flat"); + glWindow.display(); + + demo.setSmoothPoints(true); + snap.setMakeSnapshot(); + snap.setPostSNDetail("smooth"); + glWindow.display(); + + demo.setPointParams(2f, 40f, 0.01f, 0.0f, 0.01f, 1f); + snap.setMakeSnapshot(); + snap.setPostSNDetail("attn0"); + glWindow.display(); + + glWindow.removeGLEventListener(demo); + + glWindow.destroy(); + } + + protected void runTestGL(GLCapabilities caps, PointsDemo demo, boolean forceFFPEmu) throws InterruptedException { + // final PointsDemoES2 demo01 = new PointsDemoES2(); + runTestGL0(caps, demo); + } + + @Test + public void test01FFP__GL2() throws InterruptedException { + if(!GLProfile.isAvailable(GLProfile.GL2)) { System.err.println("GL2 n/a"); return; } + GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GL2)); + runTestGL(caps, new PointsDemoES1(), false); + } + + @Test + public void test02FFP__ES1() throws InterruptedException { + if(!GLProfile.isAvailable(GLProfile.GLES1)) { System.err.println("GLES1 n/a"); return; } + GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GLES1)); + runTestGL(caps, new PointsDemoES1(), false); + } + + @Test + public void test11GLSL_GL2() throws InterruptedException { + if(!GLProfile.isAvailable(GLProfile.GL2)) { System.err.println("GL2 n/a"); return; } + GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GL2)); + runTestGL(caps, new PointsDemoES2(), false); + } + + @Test + public void test12GLSL_ES2() throws InterruptedException { + if(!GLProfile.isAvailable(GLProfile.GLES2)) { System.err.println("GLES2 n/a"); return; } + GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GLES2)); + runTestGL(caps, new PointsDemoES2(), false); // should be FFPEmu implicit + } + + static long duration = 1000; // ms + + public static void main(String args[]) { + for(int i=0; i=0; i--) { + gl.glPointSize(pointSizes[i]); + gl.glDrawArrays(GL.GL_POINTS, i, 1); + } + + vertices.enableBuffer(gl, false); + } + + public void reshape(GLAutoDrawable glad, int x, int y, int width, int height) { + // Thread.dumpStack(); + GL2ES1 gl = glad.getGL().getGL2ES1(); + + if(-1 != swapInterval) { + gl.setSwapInterval(swapInterval); // in case switching the drawable (impl. may bound attribute there) + } + + // Set location in front of camera + gl.glMatrixMode(PMVMatrix.GL_PROJECTION); + gl.glLoadIdentity(); + glu.gluPerspective(45.0F, ( (float) width / (float) height ) / 1.0f, 1.0F, 100.0F); + //gl.glOrthof(-4.0f, 4.0f, -4.0f, 4.0f, 1.0f, 100.0f); + } + + public void dispose(GLAutoDrawable glad) { + GL2ES1 gl = glad.getGL().getGL2ES1(); + vertices.destroy(gl); + vertices = null; + } +} 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 new file mode 100644 index 000000000..8c6d7e180 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/PointsDemoES2.java @@ -0,0 +1,207 @@ +/** + * Copyright 2012 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.es2; + +import java.nio.FloatBuffer; + +import com.jogamp.common.nio.Buffers; +import com.jogamp.opengl.test.junit.jogl.demos.PointsDemo; +import com.jogamp.opengl.util.GLArrayDataServer; +import com.jogamp.opengl.util.PMVMatrix; +import com.jogamp.opengl.util.glsl.ShaderCode; +import com.jogamp.opengl.util.glsl.ShaderProgram; +import com.jogamp.opengl.util.glsl.ShaderState; + +import javax.media.opengl.GL; +import javax.media.opengl.GL2ES1; +import javax.media.opengl.GL2ES2; +import javax.media.opengl.GL2GL3; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLUniformData; + +public class PointsDemoES2 extends PointsDemo { + ShaderState st; + PMVMatrix pmvMatrix; + GLUniformData pmvMatrixUniform; + GLArrayDataServer vertices ; + GLArrayDataServer pointSizes ; + private int swapInterval = 0; + final int edge = 8; // 8*8 + /** vec4[2]: { (sz, smooth, attnMinSz, attnMaxSz), (attnCoeff(3), attnFadeTs) } */ + private static final String mgl_PointParams = "mgl_PointParams"; + + /** ( 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 }); + + public PointsDemoES2(int swapInterval) { + this.swapInterval = swapInterval; + } + + public PointsDemoES2() { + this.swapInterval = 1; + } + + public void setSmoothPoints(boolean v) { + pointParams.put(1, v ? 1.0f : 0.0f); + } + + public void setPointParams(float minSize, float maxSize, float distAttenConst, float distAttenLinear, float distAttenQuadratic, float fadeThreshold) { + pointParams.put(2, minSize); + pointParams.put(3, maxSize); + pointParams.put(4+0, distAttenConst); + pointParams.put(4+1, distAttenLinear); + pointParams.put(4+2, distAttenQuadratic); + pointParams.put(4+3, fadeThreshold); + } + + public void init(GLAutoDrawable glad) { + GL2ES2 gl = glad.getGL().getGL2ES2(); + + 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 Profile: "+gl.getGLProfile()); + + st = new ShaderState(); + st.setVerbose(true); + final ShaderCode vp0 = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, this.getClass(), "shader", + "shader/bin", "PointsShader", false); + final ShaderCode fp0 = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, this.getClass(), "shader", + "shader/bin", "PointsShader", false); + final ShaderProgram sp0 = new ShaderProgram(); + sp0.add(gl, vp0, System.err); + sp0.add(gl, fp0, System.err); + st.attachShaderProgram(gl, sp0, true); + + // setup mgl_PMVMatrix + pmvMatrix = new PMVMatrix(); + pmvMatrix.glMatrixMode(PMVMatrix.GL_PROJECTION); + pmvMatrix.glLoadIdentity(); + pmvMatrix.glMatrixMode(PMVMatrix.GL_MODELVIEW); + pmvMatrix.glLoadIdentity(); + pmvMatrixUniform = new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf()); // P, Mv + st.ownUniform(pmvMatrixUniform); + st.uniform(gl, pmvMatrixUniform); + + st.uniform(gl, new GLUniformData(mgl_PointParams, 4, pointParams)); + + final GLUniformData colorStaticUniform = new GLUniformData("mgl_ColorStatic", 4, Buffers.newDirectFloatBuffer(new float[] { 1.0f, 1.0f, 1.0f, 1.0f }) ); + st.uniform(gl, colorStaticUniform); + st.ownUniform(colorStaticUniform); + + // Allocate Vertex Array + vertices = GLArrayDataServer.createGLSL("mgl_Vertex", 3, GL.GL_FLOAT, false, edge*edge, GL.GL_STATIC_DRAW); + pointSizes = GLArrayDataServer.createGLSL("mgl_PointSize", 1, GL.GL_FLOAT, false, edge*edge, GL.GL_STATIC_DRAW); + for(int i=0; i 0.5 ) { + // smooth (AA) + const float border = 0.90; // take/give 10% for AA + + // origin to 0/0, [-1/-1 .. 1/1] + vec2 pointPos = 2.0 * gl_PointCoord - 1.0 ; + float r = length( pointPos ); // one-circle sqrt(x * x + y * y), range: in-circle [0..1], out >1 + float r1 = 1.0 - ( step(border, r) * 10.0 * ( r - border ) ) ; // [0..1] + #ifndef TEST + if( r1 < 0.0 ) { + discard; + } + #endif + + #ifndef TEST + gl_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; + #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 new file mode 100644 index 000000000..5043a652b --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/PointsShader.vp @@ -0,0 +1,42 @@ + +uniform vec4 mgl_ColorStatic; +uniform mat4 mgl_PMVMatrix[4]; // P, Mv, Mvi and Mvit (transpose(inverse(ModelView)) == normalMatrix) + +// [0].rgba: 0, smooth, attnMinSz, attnMaxSz +// [1].rgba: attnCoeff(3), attnFadeTs +uniform vec4 mgl_PointParams[2]; + +#define pointSmooth (mgl_PointParams[0].g) +#define pointSizeMin (mgl_PointParams[0].b) +#define pointSizeMax (mgl_PointParams[0].a) +#define pointDistanceConstantAtten (mgl_PointParams[1].r) +#define pointDistanceLinearAtten (mgl_PointParams[1].g) +#define pointDistanceQuadraticAtten (mgl_PointParams[1].b) +#define pointFadeThresholdSize (mgl_PointParams[1].a) + +attribute vec4 mgl_Vertex; +attribute float mgl_PointSize; + +varying vec4 frontColor; + +void main(void) +{ + frontColor = mgl_ColorStatic; + + vec4 eyeCoord = mgl_PMVMatrix[1] * mgl_Vertex; + gl_Position = mgl_PMVMatrix[0] * eyeCoord; + + float dist = distance(eyeCoord, vec4(0.0, 0.0, 0.0, 1.0)); + float atten = sqrt( 1.0 / ( pointDistanceConstantAtten + + ( pointDistanceLinearAtten + + pointDistanceQuadraticAtten * dist + ) * dist + ) + ); + float size = clamp(mgl_PointSize * atten, pointSizeMin, pointSizeMax); + gl_PointSize = max(size, pointFadeThresholdSize); + + float fade = min(size, pointFadeThresholdSize) / pointFadeThresholdSize; + frontColor.a *= fade * fade; +} + -- cgit v1.2.3 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(-) (limited to 'src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders') 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 From c2b328ea96b6cb16ca39f13d4bb4d1236c4b8a1d Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Wed, 31 Oct 2012 14:40:44 +0100 Subject: Shader: Add '#define texture2D texture' for GLSL >= 130 ; TestGearsES2AWT add forceGL3; TextureDraw01ES2Listener uses defaultShaderCustomization() --- make/scripts/tests.sh | 5 +++-- .../glsl/fixedfunc/shaders/FixedFuncColorTexture.fp | 1 + .../junit/jogl/demos/es2/TextureDraw01ES2Listener.java | 17 ++--------------- .../test/junit/jogl/demos/es2/awt/TestGearsES2AWT.java | 14 +++++++++++++- .../junit/jogl/demos/es2/newt/TestGearsES2NEWT.java | 1 + .../junit/jogl/demos/es2/newt/TestRedSquareES2NEWT.java | 1 + .../es2/shader/elektronenmultiplizierer_development.fp | 1 + .../demos/es2/shader/elektronenmultiplizierer_port.fp | 1 + .../test/junit/jogl/demos/es2/shader/texture01_xxx.fp | 1 + .../test/junit/jogl/demos/es2/shader/texture02_xxx.fp | 1 + 10 files changed, 25 insertions(+), 18 deletions(-) (limited to 'src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders') diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh index 6c0095c51..9595bf9f7 100755 --- a/make/scripts/tests.sh +++ b/make/scripts/tests.sh @@ -65,6 +65,7 @@ function jrun() { #D_ARGS="-Djogl.debug.DebugGL -Djogl.debug.FBObject" #D_ARGS="-Djogl.debug.FBObject -Djogl.debug.TraceGL -Djogl.debug.GLBufferStateTracker" #D_ARGS="-Djogl.debug.FBObject" + #D_ARGS="-Djogl.debug.GLSLCode" #D_ARGS="-Djogl.debug.GLSLCode -Djogl.debug.DebugGL -Djogl.debug.TraceGL" #D_ARGS="-Djogl.debug.FixedFuncPipeline -Djogl.debug.GLSLCode" #D_ARGS="-Djogl.debug.FixedFuncPipeline -Djogl.debug.GLSLState" @@ -285,7 +286,7 @@ function testawtswt() { #testawt com.jogamp.opengl.test.junit.jogl.awt.TestBug461FBOSupersamplingSwingAWT #testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT $* -#testawt com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGearsES2AWT $* +testawt com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGearsES2AWT $* #testnoawt com.jogamp.opengl.test.junit.newt.parenting.TestParenting01NEWT $* #testnoawt com.jogamp.opengl.test.junit.newt.parenting.TestParenting02NEWT $* @@ -379,7 +380,7 @@ function testawtswt() { #testawt com.jogamp.opengl.test.junit.newt.TestNewtKeyEventAutoRepeatAWT $* #testawt com.jogamp.opengl.test.junit.newt.TestNewtKeyPressReleaseUnmaskRepeatAWT $* #testawt com.jogamp.opengl.test.junit.newt.TestNewtKeyCodesAWT $* -testawt com.jogamp.opengl.test.junit.newt.TestNewtKeyCodeModifiersAWT $* +#testawt com.jogamp.opengl.test.junit.newt.TestNewtKeyCodeModifiersAWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT $* #testawt com.jogamp.opengl.test.junit.newt.TestListenerCom01AWT #testawt com.jogamp.opengl.test.junit.newt.parenting.TestParenting01aAWT $* 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 82dfa24e1..130711e19 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 @@ -2,6 +2,7 @@ #if __VERSION__ >= 130 #define varying in out vec4 mgl_FragColor; + #define texture2D texture #else #define mgl_FragColor gl_FragColor #endif diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/TextureDraw01ES2Listener.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/TextureDraw01ES2Listener.java index 6e701658c..4bcb073dc 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/TextureDraw01ES2Listener.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/TextureDraw01ES2Listener.java @@ -62,8 +62,6 @@ public class TextureDraw01ES2Listener implements GLEventListener, TextureDraw01A this.textureData = td; } - static final String[] es2_prelude = { "#version 100\n", "precision mediump float;\n" }; - static final String gl2_prelude = "#version 110\n"; static final String shaderBasename = "texture01_xxx"; private void initShader(GL2ES2 gl, boolean use_program) { @@ -72,19 +70,8 @@ public class TextureDraw01ES2Listener implements GLEventListener, TextureDraw01A "shader", "shader/bin", shaderBasename, true); ShaderCode rsFp = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, this.getClass(), "shader", "shader/bin", shaderBasename, true); - - // Prelude shader code w/ GLSL profile specifics [ 1. pre-proc, 2. other ] - int rsFpPos; - if(gl.isGLES2()) { - rsVp.insertShaderSource(0, 0, es2_prelude[0]); - rsFpPos = rsFp.insertShaderSource(0, 0, es2_prelude[0]); - } else { - rsVp.insertShaderSource(0, 0, gl2_prelude); - rsFpPos = rsFp.insertShaderSource(0, 0, gl2_prelude); - } - if(gl.isGLES2()) { - rsFpPos = rsFp.insertShaderSource(0, rsFpPos, es2_prelude[1]); - } + rsVp.defaultShaderCustomization(gl, true, ShaderCode.es2_default_precision_vp); + rsFp.defaultShaderCustomization(gl, true, ShaderCode.es2_default_precision_fp); // Create & Link the shader program ShaderProgram sp = new ShaderProgram(); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2AWT.java index c97054d18..07899b7d6 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2AWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2AWT.java @@ -61,6 +61,7 @@ import org.junit.Test; public class TestGearsES2AWT extends UITestCase { static int width, height; static boolean forceES2 = false; + static boolean forceGL3 = false; static boolean shallUseOffscreenLayer = false; static boolean shallUseOffscreenPBufferLayer = false; static boolean useMSAA = false; @@ -145,7 +146,15 @@ public class TestGearsES2AWT extends UITestCase { @Test public void test01() throws InterruptedException, InvocationTargetException { - 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(); + } + final GLCapabilities caps = new GLCapabilities(glp); if(useMSAA) { caps.setNumSamples(4); caps.setSampleBuffers(true); @@ -172,6 +181,8 @@ public class TestGearsES2AWT extends UITestCase { } catch (Exception ex) { ex.printStackTrace(); } } else if(args[i].equals("-es2")) { forceES2 = true; + } else if(args[i].equals("-gl3")) { + forceGL3 = true; } else if(args[i].equals("-vsync")) { i++; swapInterval = MiscUtils.atoi(args[i], swapInterval); @@ -197,6 +208,7 @@ public class TestGearsES2AWT extends UITestCase { } } System.err.println("forceES2 "+forceES2); + System.err.println("forceGL3 "+forceGL3); System.err.println("swapInterval "+swapInterval); System.err.println("shallUseOffscreenLayer "+shallUseOffscreenLayer); 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 90f2ab988..86831a6fa 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 @@ -372,6 +372,7 @@ public class TestGearsES2NEWT extends UITestCase { System.err.println("loops "+loops); System.err.println("loop shutdown "+loop_shutdown); System.err.println("forceES2 "+forceES2); + System.err.println("forceGL3 "+forceGL3); if(waitForKey) { BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestRedSquareES2NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestRedSquareES2NEWT.java index 21c09f78c..dbba4fae5 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestRedSquareES2NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestRedSquareES2NEWT.java @@ -183,6 +183,7 @@ public class TestRedSquareES2NEWT extends UITestCase { System.err.println("loops "+loops); System.err.println("loop shutdown "+loop_shutdown); System.err.println("forceES2 "+forceES2); + System.err.println("forceGL3 "+forceGL3); org.junit.runner.JUnitCore.main(TestRedSquareES2NEWT.class.getName()); } } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/elektronenmultiplizierer_development.fp b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/elektronenmultiplizierer_development.fp index 2414af5dc..60f054b46 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/elektronenmultiplizierer_development.fp +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/elektronenmultiplizierer_development.fp @@ -12,6 +12,7 @@ #if __VERSION__ >= 130 #define varying in out vec4 mgl_FragColor; + #define texture2D texture #else #define mgl_FragColor gl_FragColor #endif diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/elektronenmultiplizierer_port.fp b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/elektronenmultiplizierer_port.fp index ce0b8f5aa..77c34f74f 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/elektronenmultiplizierer_port.fp +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/elektronenmultiplizierer_port.fp @@ -15,6 +15,7 @@ #if __VERSION__ >= 130 #define varying in out vec4 mgl_FragColor; + #define texture2D texture #else #define mgl_FragColor gl_FragColor #endif diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/texture01_xxx.fp b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/texture01_xxx.fp index 4cf1d9d10..c213f3ab4 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/texture01_xxx.fp +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/texture01_xxx.fp @@ -3,6 +3,7 @@ #if __VERSION__ >= 130 #define varying in out vec4 mgl_FragColor; + #define texture2D texture #else #define mgl_FragColor gl_FragColor #endif diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/texture02_xxx.fp b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/texture02_xxx.fp index e15d7a154..10073e85c 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/texture02_xxx.fp +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/texture02_xxx.fp @@ -3,6 +3,7 @@ #if __VERSION__ >= 130 #define varying in out vec4 mgl_FragColor; + #define texture2D texture #else #define mgl_FragColor gl_FragColor #endif -- cgit v1.2.3