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. --- .../util/glsl/fixedfunc/FixedFuncPipeline.java | 119 ++++++--------------- 1 file changed, 35 insertions(+), 84 deletions(-) (limited to 'src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncPipeline.java') 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" ; -- cgit v1.2.3