diff options
Diffstat (limited to 'src/jogl/classes/jogamp/graph/curve')
15 files changed, 141 insertions, 134 deletions
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/RegionFactory.java b/src/jogl/classes/jogamp/graph/curve/opengl/RegionFactory.java new file mode 100755 index 000000000..b5a89b40a --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/RegionFactory.java @@ -0,0 +1,64 @@ +/**
+ * Copyright 2010 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 jogamp.graph.curve.opengl;
+
+import com.jogamp.graph.curve.Region;
+import com.jogamp.graph.curve.opengl.GLRegion;
+
+/** RegionFactory to create a Context specific Region implementation.
+ *
+ * @see GLRegion
+ */
+public class RegionFactory {
+
+ /**
+ * Create a Region using the passed render mode
+ *
+ * <p> In case {@link Region#TWO_PASS_RENDERING_BIT} is being requested the default texture unit
+ * {@link Region#TWO_PASS_DEFAULT_TEXTURE_UNIT} is being used.</p>
+ *
+ * @param rs the RenderState to be used
+ * @param renderModes bit-field of modes, e.g. {@link Region#VARIABLE_CURVE_WEIGHT_BIT}, {@link Region#TWO_PASS_RENDERING_BIT}
+ */
+ public static GLRegion create(int renderModes) {
+ if( 0 != ( Region.TWO_PASS_RENDERING_BIT & renderModes ) ){
+ return new VBORegion2PES2(renderModes, Region.TWO_PASS_DEFAULT_TEXTURE_UNIT);
+ }
+ else{
+ return new VBORegionSPES2(renderModes);
+ }
+ }
+
+ public static GLRegion createSinglePass(int renderModes) {
+ return new VBORegionSPES2(renderModes);
+ }
+
+ public static GLRegion createTwoPass(int renderModes, int textureUnit) {
+ return new VBORegion2PES2(renderModes, textureUnit);
+ }
+}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java b/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java index 09e94d618..dcfe3cae0 100755 --- a/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java @@ -32,8 +32,8 @@ import javax.media.opengl.GLException; import jogamp.graph.curve.opengl.shader.AttributeNames;
-import com.jogamp.graph.curve.OutlineShape;
import com.jogamp.graph.curve.Region;
+import com.jogamp.graph.curve.opengl.GLRegion;
import com.jogamp.graph.curve.opengl.RegionRenderer;
import com.jogamp.graph.curve.opengl.RenderState;
import com.jogamp.opengl.util.glsl.ShaderCode;
@@ -41,29 +41,26 @@ import com.jogamp.opengl.util.glsl.ShaderProgram; import com.jogamp.opengl.util.glsl.ShaderState;
public class RegionRendererImpl01 extends RegionRenderer {
- public RegionRendererImpl01(RenderState rs, int type, boolean uniform) {
- super(rs, type, uniform);
+ public RegionRendererImpl01(RenderState rs, int renderModes) {
+ super(rs, renderModes);
}
- private String getVertexShaderName(){
- return "curverenderer01";
- }
-
- private String getFragmentShaderName(){
- if(!isUniformWeight()){
- return "curverenderer02";
+ @Override
+ protected String getFragmentShaderName(GL2ES2 gl) {
+ if(Region.usesVariableCurveWeight(renderModes)){
+ return "curverenderer02" + getShaderGLVersionSuffix(gl);
}
- return "curverenderer01";
+ return "curverenderer01" + getShaderGLVersionSuffix(gl);
}
protected boolean initShaderProgram(GL2ES2 gl) {
final ShaderState st = rs.getShaderState();
ShaderCode rsVp = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, 1, RegionRendererImpl01.class,
- "shader", "shader/bin", getVertexShaderName());
+ "shader", "shader/bin", getVertexShaderName(gl));
ShaderCode rsFp = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, 1, RegionRendererImpl01.class,
- "shader", "shader/bin", getFragmentShaderName());
+ "shader", "shader/bin", getFragmentShaderName(gl));
ShaderProgram sp = new ShaderProgram();
sp.add(rsVp);
@@ -86,39 +83,12 @@ public class RegionRendererImpl01 extends RegionRenderer { }
@Override
- protected void disposeImpl(GL2ES2 gl) {
- super.disposeImpl(gl);
- }
-
-
- @Override
- public void renderOutlineShape(GL2ES2 gl, OutlineShape outlineShape, float[] position, int texSize) {
- if(!isInitialized()){
- throw new GLException("RegionRendererImpl01: not initialized!");
- }
- int hashCode = getHashCode(outlineShape);
- Region region = regions.get(hashCode);
-
- if(null == region) {
- region = createRegion(gl, outlineShape);
- regions.put(hashCode, region);
- }
- region.render(gl, rs, vp_width, vp_height, texSize);
+ protected void destroyImpl(GL2ES2 gl) {
+ super.destroyImpl(gl);
}
-
+
@Override
- public void renderOutlineShapes(GL2ES2 gl, OutlineShape[] outlineShapes, float[] position, int texSize) {
- if(!isInitialized()){
- throw new GLException("RegionRendererImpl01: not initialized!");
- }
-
- int hashCode = getHashCode(outlineShapes);
- Region region = regions.get(hashCode);
-
- if(null == region) {
- region = createRegion(gl, outlineShapes);
- regions.put(hashCode, region);
- }
- region.render(gl, rs, vp_width, vp_height, texSize);
+ protected void drawImpl(GL2ES2 gl, Region region, float[] position, int texSize) {
+ ((GLRegion)region).draw(gl, rs, vp_width, vp_height, texSize);
}
}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/RenderStateImpl.java b/src/jogl/classes/jogamp/graph/curve/opengl/RenderStateImpl.java index 350c77d98..996ab4c02 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/RenderStateImpl.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/RenderStateImpl.java @@ -31,23 +31,15 @@ import java.nio.FloatBuffer; import javax.media.opengl.GL2ES2; import javax.media.opengl.GLUniformData; -import javax.media.opengl.fixedfunc.GLMatrixFunc; import jogamp.graph.curve.opengl.shader.UniformNames; -import com.jogamp.common.os.Platform; import com.jogamp.graph.curve.opengl.RenderState; import com.jogamp.graph.geom.Vertex; import com.jogamp.opengl.util.PMVMatrix; import com.jogamp.opengl.util.glsl.ShaderState; -public class RenderStateImpl implements RenderState { - - private final ShaderState st; - private final Vertex.Factory<? extends Vertex> pointFactory; - private final PMVMatrix pmvMatrix; - private final GLUniformData gcu_PMVMatrix; - +public class RenderStateImpl extends RenderState { /** * weight is equivalent to the * global off-curve vertex weight. @@ -62,11 +54,7 @@ public class RenderStateImpl implements RenderState { } public RenderStateImpl(ShaderState st, Vertex.Factory<? extends Vertex> pointFactory, PMVMatrix pmvMatrix) { - this.st = st; - this.pointFactory = pointFactory; - this.pmvMatrix = pmvMatrix; - this.gcu_PMVMatrix = new GLUniformData(UniformNames.gcu_PMVMatrix, 4, 4, pmvMatrix.glGetPMvMatrixf()); - st.ownUniform(gcu_PMVMatrix); + super(st, pointFactory, pmvMatrix); gcu_Weight = new GLUniformData(UniformNames.gcu_Weight, 1.0f); st.ownUniform(gcu_PMVMatrix); @@ -80,53 +68,12 @@ public class RenderStateImpl implements RenderState { public RenderStateImpl(ShaderState st, Vertex.Factory<? extends Vertex> pointFactory) { this(st, pointFactory, new PMVMatrix()); - - pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION); - pmvMatrix.glLoadIdentity(); - pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); - pmvMatrix.glLoadIdentity(); - pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION); - pmvMatrix.glLoadIdentity(); } - public final ShaderState getShaderState() { return st; } - public final Vertex.Factory<? extends Vertex> getPointFactory () { return pointFactory; } - public final PMVMatrix pmvMatrix() { return pmvMatrix; } - public final GLUniformData getPMVMatrix() { return gcu_PMVMatrix; } public final GLUniformData getWeight() { return gcu_Weight; } public final GLUniformData getAlpha() { return gcu_Alpha; } public final GLUniformData getColorStatic() { return gcu_ColorStatic; } //public final GLUniformData getStrength() { return gcu_Strength; } - public void destroy(GL2ES2 gl) { - st.destroy(gl); - } - - public final RenderState attachTo(GL2ES2 gl) { - return (RenderState) gl.getContext().attachObject(RenderState.class.getName(), this); - } - public final boolean detachFrom(GL2ES2 gl) { - RenderState _rs = (RenderState) gl.getContext().getAttachedObject(RenderState.class.getName()); - if(_rs == this) { - gl.getContext().detachObject(RenderState.class.getName()); - return true; - } - return false; - } - - public StringBuilder toString(StringBuilder sb) { - if(null==sb) { - sb = new StringBuilder(); - } - - sb.append("RenderState["); - st.toString(sb).append(Platform.getNewline()); - sb.append("]"); - - return sb; - } - public String toString() { - return toString(null).toString(); - } } diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java b/src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java index 257d05fca..5ed3529bf 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java @@ -48,11 +48,11 @@ public class TextRendererImpl01 extends TextRenderer { @Override protected boolean initShaderProgram(GL2ES2 gl){ final ShaderState st = rs.getShaderState(); - + ShaderCode rsVp = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, 1, TextRendererImpl01.class, - "shader", "shader/bin", "curverenderer01"); + "shader", "shader/bin", getVertexShaderName(gl)); ShaderCode rsFp = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, 1, TextRendererImpl01.class, - "shader", "shader/bin", "curverenderer01"); + "shader", "shader/bin", getFragmentShaderName(gl)); ShaderProgram sp = new ShaderProgram(); sp.add(rsVp); @@ -75,12 +75,12 @@ public class TextRendererImpl01 extends TextRenderer { } @Override - protected void disposeImpl(GL2ES2 gl) { - super.disposeImpl(gl); + protected void destroyImpl(GL2ES2 gl) { + super.destroyImpl(gl); } @Override - public void renderString3D(GL2ES2 gl, Font font, String str, float[] position, int fontSize, int texSize) { + public void drawString3D(GL2ES2 gl, Font font, String str, float[] position, int fontSize, int texSize) { if(!isInitialized()){ throw new GLException("TextRendererImpl01: not initialized!"); } diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/UniformNames.java b/src/jogl/classes/jogamp/graph/curve/opengl/shader/UniformNames.java index bb6ff987d..ab6e0dc6e 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/UniformNames.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/UniformNames.java @@ -6,4 +6,5 @@ public class UniformNames { public static final String gcu_Alpha = "gcu_Alpha"; public static final String gcu_Weight = "gcu_Weight"; public static final String gcu_TextureUnit = "gcu_TextureUnit"; + public static final String gcu_TextureSize = "gcu_TextureSize"; } diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-es2.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-es2.fp new file mode 100644 index 000000000..0131f38b0 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-es2.fp @@ -0,0 +1,6 @@ +//Copyright 2010 JogAmp Community. All rights reserved. + +#version 100 + +#include curverenderer01-xxx.fp + diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-es2.vp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-es2.vp new file mode 100644 index 000000000..8c0585b1d --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-es2.vp @@ -0,0 +1,6 @@ +//Copyright 2010 JogAmp Community. All rights reserved. + +#version 100 + +#include curverenderer01-xxx.vp + diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-gl2.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-gl2.fp new file mode 100644 index 000000000..ba4c7daa0 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-gl2.fp @@ -0,0 +1,6 @@ +//Copyright 2010 JogAmp Community. All rights reserved. + +#version 110 + +#include curverenderer01-xxx.fp + diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-gl2.vp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-gl2.vp new file mode 100644 index 000000000..1ac33e8b3 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-gl2.vp @@ -0,0 +1,6 @@ +//Copyright 2010 JogAmp Community. All rights reserved. + +#version 110 + +#include curverenderer01-xxx.vp + diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-xxx.fp index b3693ec88..e50aea04d 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.fp +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-xxx.fp @@ -1,14 +1,5 @@ //Copyright 2010 JogAmp Community. All rights reserved. -/** - * AMD complains: #version must occur before any other statement in the program -#ifdef GL_ES - #version 100 -#else - #version 110 -#endif - */ - #include uniforms.glsl #include varyings.glsl @@ -29,7 +20,12 @@ void main (void) vec2 dfx = dFdx(gcv_TexCoord); vec2 dfy = dFdy(gcv_TexCoord); - vec2 size = 1.0/textureSize(gcu_TextureUnit,0); //version 130 - FIXME: replace with uniform value + vec2 size; + //#if __VERSION__ < 130 + size = 1.0/gcu_TextureSize; + //#else + // size = 1.0/textureSize(gcu_TextureUnit,0); + //#endif rtex -= 5.0; vec4 t = texture2D(gcu_TextureUnit, rtex)* 0.18; diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.vp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-xxx.vp index fe74caffb..64a6835ec 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.vp +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-xxx.vp @@ -1,14 +1,5 @@ //Copyright 2010 JogAmp Community. All rights reserved. -/** - * AMD complains: #version must occur before any other statement in the program -#ifdef GL_ES - #version 100 -#else - #version 110 -#endif - */ - #include uniforms.glsl #include attributes.glsl #include varyings.glsl diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02-es2.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02-es2.fp new file mode 100644 index 000000000..358e68b81 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02-es2.fp @@ -0,0 +1,6 @@ +//Copyright 2010 JogAmp Community. All rights reserved. + +#version 100 + +#include curverenderer02-xxx.fp + diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02-gl2.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02-gl2.fp new file mode 100644 index 000000000..d7fe31a08 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02-gl2.fp @@ -0,0 +1,6 @@ +//Copyright 2010 JogAmp Community. All rights reserved. + +#version 110 + +#include curverenderer02-xxx.fp + diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02-xxx.fp index e3d5bc074..c6a3c56c8 100755..100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02.fp +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02-xxx.fp @@ -1,11 +1,4 @@ //Copyright 2010 JogAmp Community. All rights reserved.
-/**
-#ifdef GL_ES
- #version 100
-#else
- #version 110
-#endif
- */
#include uniforms.glsl
#include varyings.glsl
@@ -27,7 +20,12 @@ void main (void) vec2 dfx = dFdx(gcv_TexCoord);
vec2 dfy = dFdy(gcv_TexCoord);
- vec2 size = 1.0/textureSize(gcu_TextureUnit,0); //version 130 - FIXME: replace with uniform value
+ // vec2 size;
+ //#if __VERSION__ < 130
+ vec2 size = 1.0/gcu_TextureSize;
+ //#else
+ // size = 1.0/textureSize(gcu_TextureUnit,0);
+ //#endif
rtex -= 5.0;
vec4 t = texture2D(gcu_TextureUnit, rtex)* 0.18;
@@ -79,7 +77,7 @@ void main (void) float aph = 2.0 - 2.0*w;
float gd = (aph*rtex.x*rtex.x + 2.0*rtex.x + 1.0)*(aph*rtex.x*rtex.x + 2.0*rtex.x + 1.0);
- vec2 f = vec2((dtx.y - (w*dtx.x*(1.0 - 2*rtex.x))/gd), (dty.y - (w*dty.x*(1.0 - 2*rtex.x))/gd));
+ vec2 f = vec2((dtx.y - (w*dtx.x*(1.0 - 2.0*rtex.x))/gd), (dty.y - (w*dty.x*(1.0 - 2.0*rtex.x))/gd));
float d = position/(length(f));
float a = (0.5 - d * sign(gcv_TexCoord.y));
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl index 332edd02b..6b3d846a3 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl @@ -12,6 +12,10 @@ uniform HIGHP float gcu_Alpha; uniform HIGHP float gcu_Weight; uniform sampler2D gcu_TextureUnit; +// #if __VERSION__ < 130 + uniform HIGHP vec2 gcu_TextureSize; +// #endif + // uniform HIGHP mat3 gcu_NormalMatrix; // transpose(inverse(ModelView)).3x3 // uniform LOWP int gcu_ColorEnabled; // uniform LOWP int gcu_TexCoordEnabled[MAX_TEXTURE_UNITS]; |