aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/jogamp/graph/curve/opengl
diff options
context:
space:
mode:
Diffstat (limited to 'src/jogl/classes/jogamp/graph/curve/opengl')
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/RegionFactory.java74
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java19
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java108
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java343
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java411
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java408
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java134
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-1pass_norm-weight.fp (renamed from src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-1pass-weight.fp)27
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-1pass_norm.fp (renamed from src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-1pass.fp)35
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass-weight.fp97
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass.fp91
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_msaa-weight.fp76
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_msaa.fp88
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_vbaa-weight.fp109
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_vbaa.fp103
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl7
16 files changed, 1301 insertions, 829 deletions
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/RegionFactory.java b/src/jogl/classes/jogamp/graph/curve/opengl/RegionFactory.java
deleted file mode 100644
index 515583b14..000000000
--- a/src/jogl/classes/jogamp/graph/curve/opengl/RegionFactory.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/**
- * 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#VBAA_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#VBAA_RENDERING_BIT}
- */
- public static GLRegion create(int renderModes) {
- if( 0 != ( Region.VBAA_RENDERING_BIT & renderModes ) ){
- return new VBORegion2PES2(renderModes, Region.TWO_PASS_DEFAULT_TEXTURE_UNIT);
- }
- else{
- return new VBORegionSPES2(renderModes);
- }
- }
-
- /** Create a Single Pass Region using the passed render mode
- * @param renderModes bit-field of modes, e.g. {@link Region#VARIABLE_CURVE_WEIGHT_BIT},
- * {@link Region#VBAA_RENDERING_BIT}
- * @return
- */
- public static GLRegion createSinglePass(int renderModes) {
- return new VBORegionSPES2(renderModes);
- }
-
- /** Create a Two Pass (VBAA) Region using the passed render mode
- * @param renderModes bit-field of modes, e.g. {@link Region#VARIABLE_CURVE_WEIGHT_BIT},
- * {@link Region#VBAA_RENDERING_BIT}
- * @return
- */
- 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 31ad974d0..e50caa663 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java
@@ -32,23 +32,21 @@ import javax.media.opengl.GLException;
import jogamp.graph.curve.opengl.shader.AttributeNames;
-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.graph.curve.opengl.RegionRenderer;
import com.jogamp.opengl.GLExtensions;
import com.jogamp.opengl.util.glsl.ShaderCode;
import com.jogamp.opengl.util.glsl.ShaderProgram;
import com.jogamp.opengl.util.glsl.ShaderState;
public class RegionRendererImpl01 extends RegionRenderer {
- public RegionRendererImpl01(RenderState rs, int renderModes) {
- super(rs, renderModes);
+ public RegionRendererImpl01(final RenderState rs, final int renderModes, final GLCallback enableCallback, final GLCallback disableCallback) {
+ super(rs, renderModes, enableCallback, disableCallback);
}
@Override
- protected boolean initShaderProgram(GL2ES2 gl) {
+ protected final boolean initImpl(GL2ES2 gl) {
final ShaderState st = rs.getShaderState();
final ShaderCode rsVp = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, RegionRendererImpl01.class, "shader",
@@ -89,12 +87,7 @@ public class RegionRendererImpl01 extends RegionRenderer {
}
@Override
- protected void destroyImpl(GL2ES2 gl) {
- super.destroyImpl(gl);
- }
-
- @Override
- protected void drawImpl(GL2ES2 gl, Region region, float[] position, int[] texSize) {
- ((GLRegion)region).draw(gl, rs, vp_width, vp_height, texSize);
+ protected final void destroyImpl(GL2ES2 gl) {
+ // NOP .. all will be destroyed via RenderState
}
}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java b/src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java
deleted file mode 100644
index 4ec4d1d98..000000000
--- a/src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/**
- * 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 javax.media.opengl.GL2ES2;
-import javax.media.opengl.GLException;
-
-import jogamp.graph.curve.opengl.shader.AttributeNames;
-import jogamp.graph.curve.text.GlyphString;
-
-import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.graph.curve.opengl.TextRenderer;
-import com.jogamp.graph.font.Font;
-import com.jogamp.opengl.GLExtensions;
-import com.jogamp.opengl.util.glsl.ShaderCode;
-import com.jogamp.opengl.util.glsl.ShaderProgram;
-import com.jogamp.opengl.util.glsl.ShaderState;
-
-public class TextRendererImpl01 extends TextRenderer {
- public TextRendererImpl01(RenderState rs, int type) {
- super(rs, type);
- }
-
- @Override
- protected boolean initShaderProgram(GL2ES2 gl){
- final ShaderState st = rs.getShaderState();
-
- final ShaderCode rsVp = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, TextRendererImpl01.class, "shader",
- "shader/bin", getVertexShaderName(), true);
- final ShaderCode rsFp = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, TextRendererImpl01.class, "shader",
- "shader/bin", getFragmentShaderName(), true);
- rsVp.defaultShaderCustomization(gl, true, true);
- // rsFp.defaultShaderCustomization(gl, true, true);
- int pos = rsFp.addGLSLVersion(gl);
- if( gl.isGLES() ) {
- pos = rsFp.insertShaderSource(0, pos, ShaderCode.createExtensionDirective(GLExtensions.OES_standard_derivatives, ShaderCode.ENABLE));
- }
- final String rsFpDefPrecision = getFragmentShaderPrecision(gl);
- if( null != rsFpDefPrecision ) {
- rsFp.insertShaderSource(0, pos, rsFpDefPrecision);
- }
-
- final ShaderProgram sp = new ShaderProgram();
- sp.add(rsVp);
- sp.add(rsFp);
-
- if( !sp.init(gl) ) {
- throw new GLException("RegionRenderer: Couldn't init program: "+sp);
- }
- st.attachShaderProgram(gl, sp, false);
- st.bindAttribLocation(gl, AttributeNames.VERTEX_ATTR_IDX, AttributeNames.VERTEX_ATTR_NAME);
- st.bindAttribLocation(gl, AttributeNames.TEXCOORD_ATTR_IDX, AttributeNames.TEXCOORD_ATTR_NAME);
-
- if(!sp.link(gl, System.err)) {
- throw new GLException("TextRendererImpl01: Couldn't link program: "+sp);
- }
- st.useProgram(gl, true);
-
- if(DEBUG) {
- System.err.println("TextRendererImpl01 initialized: " + Thread.currentThread()+" "+st);
- }
- return true;
- }
-
- @Override
- protected void destroyImpl(GL2ES2 gl) {
- super.destroyImpl(gl);
- }
-
- @Override
- public void drawString3D(GL2ES2 gl, Font font, String str, float[] position, int fontSize, int[/*1*/] texSize) {
- if(!isInitialized()){
- throw new GLException("TextRendererImpl01: not initialized!");
- }
- GlyphString glyphString = getCachedGlyphString(font, str, fontSize);
- if(null == glyphString) {
- glyphString = createString(gl, font, fontSize, str);
- addCachedGlyphString(gl, font, str, fontSize, glyphString);
- }
-
- glyphString.renderString3D(gl, rs, vp_width, vp_height, texSize);
- }
-}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java
deleted file mode 100644
index 77c862ed4..000000000
--- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java
+++ /dev/null
@@ -1,343 +0,0 @@
-/**
- * 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 java.nio.FloatBuffer;
-
-import javax.media.opengl.GL2ES2;
-// FIXME: Subsume GL2GL3.GL_DRAW_FRAMEBUFFER -> GL2ES2.GL_DRAW_FRAMEBUFFER !
-import javax.media.opengl.GL;
-import javax.media.opengl.GLUniformData;
-import javax.media.opengl.fixedfunc.GLMatrixFunc;
-
-import jogamp.graph.curve.opengl.shader.AttributeNames;
-import jogamp.graph.curve.opengl.shader.UniformNames;
-
-import com.jogamp.common.nio.Buffers;
-import com.jogamp.graph.geom.Triangle;
-import com.jogamp.graph.geom.Vertex;
-
-import com.jogamp.graph.curve.opengl.GLRegion;
-import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.opengl.FBObject;
-import com.jogamp.opengl.FBObject.Attachment;
-import com.jogamp.opengl.FBObject.TextureAttachment;
-import com.jogamp.opengl.util.GLArrayDataServer;
-import com.jogamp.opengl.util.PMVMatrix;
-import com.jogamp.opengl.util.glsl.ShaderState;
-
-public class VBORegion2PES2 extends GLRegion {
- private GLArrayDataServer verticeTxtAttr;
- private GLArrayDataServer texCoordTxtAttr;
- private GLArrayDataServer indicesTxt;
- private GLArrayDataServer verticeFboAttr;
- private GLArrayDataServer texCoordFboAttr;
- private GLArrayDataServer indicesFbo;
-
-
- private FBObject fbo;
- private TextureAttachment texA;
- private PMVMatrix fboPMVMatrix;
- GLUniformData mgl_fboPMVMatrix;
-
- private int tex_width_c = 0;
- private int tex_height_c = 0;
- GLUniformData mgl_ActiveTexture;
- GLUniformData mgl_TextureSize; // if GLSL < 1.30
-
- public VBORegion2PES2(int renderModes, int textureEngine) {
- super(renderModes);
- fboPMVMatrix = new PMVMatrix();
- mgl_fboPMVMatrix = new GLUniformData(UniformNames.gcu_PMVMatrix, 4, 4, fboPMVMatrix.glGetPMvMatrixf());
- mgl_ActiveTexture = new GLUniformData(UniformNames.gcu_TextureUnit, textureEngine);
- }
-
- @Override
- public void update(GL2ES2 gl, RenderState rs) {
- if(!isDirty()) {
- return;
- }
-
- if(null == indicesFbo) {
- final int initialElementCount = 256;
- final ShaderState st = rs.getShaderState();
-
- indicesFbo = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialElementCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
- indicesFbo.puts((short) 0); indicesFbo.puts((short) 1); indicesFbo.puts((short) 3);
- indicesFbo.puts((short) 1); indicesFbo.puts((short) 2); indicesFbo.puts((short) 3);
- indicesFbo.seal(true);
-
- texCoordFboAttr = GLArrayDataServer.createGLSL(AttributeNames.TEXCOORD_ATTR_NAME, 2, GL2ES2.GL_FLOAT,
- false, initialElementCount, GL.GL_STATIC_DRAW);
- st.ownAttribute(texCoordFboAttr, true);
- texCoordFboAttr.putf(5); texCoordFboAttr.putf(5);
- texCoordFboAttr.putf(5); texCoordFboAttr.putf(6);
- texCoordFboAttr.putf(6); texCoordFboAttr.putf(6);
- texCoordFboAttr.putf(6); texCoordFboAttr.putf(5);
- texCoordFboAttr.seal(true);
-
- verticeFboAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT,
- false, initialElementCount, GL.GL_STATIC_DRAW);
- st.ownAttribute(verticeFboAttr, true);
-
-
- indicesTxt = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialElementCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
-
- verticeTxtAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT,
- false, initialElementCount, GL.GL_STATIC_DRAW);
- st.ownAttribute(verticeTxtAttr, true);
-
- texCoordTxtAttr = GLArrayDataServer.createGLSL(AttributeNames.TEXCOORD_ATTR_NAME, 2, GL2ES2.GL_FLOAT,
- false, initialElementCount, GL.GL_STATIC_DRAW);
- st.ownAttribute(texCoordTxtAttr, true);
-
- if(DEBUG_INSTANCE) {
- System.err.println("VBORegion2PES2 Create: " + this);
- }
- }
- // process triangles
- indicesTxt.seal(gl, false);
- indicesTxt.rewind();
- for(int i=0; i<triangles.size(); i++) {
- final Triangle t = triangles.get(i);
- final Vertex[] t_vertices = t.getVertices();
-
- if(t_vertices[0].getId() == Integer.MAX_VALUE){
- t_vertices[0].setId(numVertices++);
- t_vertices[1].setId(numVertices++);
- t_vertices[2].setId(numVertices++);
-
- vertices.add(t_vertices[0]);
- vertices.add(t_vertices[1]);
- vertices.add(t_vertices[2]);
-
- indicesTxt.puts((short) t_vertices[0].getId());
- indicesTxt.puts((short) t_vertices[1].getId());
- indicesTxt.puts((short) t_vertices[2].getId());
- } else {
- indicesTxt.puts((short) t_vertices[0].getId());
- indicesTxt.puts((short) t_vertices[1].getId());
- indicesTxt.puts((short) t_vertices[2].getId());
- }
- }
- indicesTxt.seal(gl, true);
- indicesTxt.enableBuffer(gl, false);
-
- // process vertices and update bbox
- box.reset();
- verticeTxtAttr.seal(gl, false);
- verticeTxtAttr.rewind();
- texCoordTxtAttr.seal(gl, false);
- texCoordTxtAttr.rewind();
- for(int i=0; i<vertices.size(); i++) {
- final Vertex v = vertices.get(i);
- verticeTxtAttr.putf(v.getX());
- verticeTxtAttr.putf(v.getY());
- verticeTxtAttr.putf(v.getZ());
- box.resize(v.getX(), v.getY(), v.getZ());
-
- final float[] tex = v.getTexCoord();
- texCoordTxtAttr.putf(tex[0]);
- texCoordTxtAttr.putf(tex[1]);
- }
- texCoordTxtAttr.seal(gl, true);
- texCoordTxtAttr.enableBuffer(gl, false);
- verticeTxtAttr.seal(gl, true);
- verticeTxtAttr.enableBuffer(gl, false);
-
- // update all bbox related data
- verticeFboAttr.seal(gl, false);
- verticeFboAttr.rewind();
- verticeFboAttr.putf(box.getLow()[0]); verticeFboAttr.putf(box.getLow()[1]); verticeFboAttr.putf(box.getLow()[2]);
- verticeFboAttr.putf(box.getLow()[0]); verticeFboAttr.putf(box.getHigh()[1]); verticeFboAttr.putf(box.getLow()[2]);
- verticeFboAttr.putf(box.getHigh()[0]); verticeFboAttr.putf(box.getHigh()[1]); verticeFboAttr.putf(box.getLow()[2]);
- verticeFboAttr.putf(box.getHigh()[0]); verticeFboAttr.putf(box.getLow()[1]); verticeFboAttr.putf(box.getLow()[2]);
- verticeFboAttr.seal(gl, true);
- verticeFboAttr.enableBuffer(gl, false);
-
- fboPMVMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
- fboPMVMatrix.glLoadIdentity();
- fboPMVMatrix.glOrthof(box.getLow()[0], box.getHigh()[0], box.getLow()[1], box.getHigh()[1], -1, 1);
-
- // push data 2 GPU ..
- indicesFbo.seal(gl, true);
- indicesFbo.enableBuffer(gl, false);
-
- setDirty(false);
-
- // the buffers were disabled, since due to real/fbo switching and other vbo usage
- }
-
- int[] maxTexSize = new int[] { -1 } ;
-
- @Override
- protected void drawImpl(GL2ES2 gl, RenderState rs, int vp_width, int vp_height, int[/*1*/] texWidth) {
- if(vp_width <=0 || vp_height <= 0 || null==texWidth || texWidth[0] <= 0){
- renderRegion(gl);
- } else {
- if(0 > maxTexSize[0]) {
- gl.glGetIntegerv(GL.GL_MAX_TEXTURE_SIZE, maxTexSize, 0);
- }
- if(texWidth[0] != tex_width_c) {
- if(texWidth[0] > maxTexSize[0]) {
- texWidth[0] = maxTexSize[0]; // clip to max - write-back user value!
- }
- renderRegion2FBO(gl, rs, texWidth);
- }
- // System.out.println("Scale: " + matrix.glGetMatrixf().get(1+4*3) +" " + matrix.glGetMatrixf().get(2+4*3));
- renderFBO(gl, rs, vp_width, vp_height);
- }
- }
-
- private void renderFBO(GL2ES2 gl, RenderState rs, int width, int hight) {
- final ShaderState st = rs.getShaderState();
-
- gl.glViewport(0, 0, width, hight);
- st.uniform(gl, mgl_ActiveTexture);
- gl.glActiveTexture(GL.GL_TEXTURE0 + mgl_ActiveTexture.intValue());
- fbo.use(gl, texA);
- verticeFboAttr.enableBuffer(gl, true);
- texCoordFboAttr.enableBuffer(gl, true);
- indicesFbo.bindBuffer(gl, true); // keeps VBO binding
-
- gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesFbo.getElementCount() * indicesFbo.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0);
-
- indicesFbo.bindBuffer(gl, false);
- texCoordFboAttr.enableBuffer(gl, false);
- verticeFboAttr.enableBuffer(gl, false);
- fbo.unuse(gl);
-
- // setback: gl.glActiveTexture(currentActiveTextureEngine[0]);
- }
-
- private void renderRegion2FBO(GL2ES2 gl, RenderState rs, int[/*1*/] texWidth) {
- final ShaderState st = rs.getShaderState();
-
- if(0>=texWidth[0]) {
- throw new IllegalArgumentException("texWidth must be greater than 0: "+texWidth[0]);
- }
-
- tex_width_c = texWidth[0];
- tex_height_c = (int) ( ( ( tex_width_c * box.getHeight() ) / box.getWidth() ) + 0.5f );
-
- // System.out.println("FBO Size: "+texWidth[0]+" -> "+tex_width_c+"x"+tex_height_c);
- // System.out.println("FBO Scale: " + m.glGetMatrixf().get(0) +" " + m.glGetMatrixf().get(5));
-
- if(null != fbo && fbo.getWidth() != tex_width_c && fbo.getHeight() != tex_height_c ) {
- fbo.reset(gl, tex_width_c, tex_height_c);
- }
-
- if(null == fbo) {
- fbo = new FBObject();
- fbo.reset(gl, tex_width_c, tex_height_c);
- // FIXME: shall not use bilinear, due to own AA ? However, w/o bilinear result is not smooth
- texA = fbo.attachTexture2D(gl, 0, true, GL2ES2.GL_LINEAR, GL2ES2.GL_LINEAR, GL2ES2.GL_CLAMP_TO_EDGE, GL2ES2.GL_CLAMP_TO_EDGE);
- // texA = fbo.attachTexture2D(gl, 0, GL2ES2.GL_NEAREST, GL2ES2.GL_NEAREST, GL2ES2.GL_CLAMP_TO_EDGE, GL2ES2.GL_CLAMP_TO_EDGE);
- fbo.attachRenderbuffer(gl, Attachment.Type.DEPTH, 24);
- } else {
- fbo.bind(gl);
- }
-
- //render texture
- gl.glViewport(0, 0, tex_width_c, tex_height_c);
- st.uniform(gl, mgl_fboPMVMatrix); // use orthogonal matrix
-
- gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
- gl.glClear(GL2ES2.GL_COLOR_BUFFER_BIT | GL2ES2.GL_DEPTH_BUFFER_BIT);
- renderRegion(gl);
- fbo.unbind(gl);
-
- st.uniform(gl, rs.getPMVMatrix()); // switch back to real PMV matrix
-
- // if( !gl.isGL3() ) {
- // GLSL < 1.30
- if(null == mgl_TextureSize) {
- mgl_TextureSize = new GLUniformData(UniformNames.gcu_TextureSize, 2, Buffers.newDirectFloatBuffer(2));
- }
- final FloatBuffer texSize = (FloatBuffer) mgl_TextureSize.getBuffer();
- texSize.put(0, (float)fbo.getWidth());
- texSize.put(1, (float)fbo.getHeight());
- st.uniform(gl, mgl_TextureSize);
- //}
- }
-
- private void renderRegion(GL2ES2 gl) {
- verticeTxtAttr.enableBuffer(gl, true);
- texCoordTxtAttr.enableBuffer(gl, true);
- indicesTxt.bindBuffer(gl, true); // keeps VBO binding
-
- gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesTxt.getElementCount() * indicesTxt.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0);
-
- indicesTxt.bindBuffer(gl, false);
- texCoordTxtAttr.enableBuffer(gl, false);
- verticeTxtAttr.enableBuffer(gl, false);
- }
-
- @Override
- public void destroy(GL2ES2 gl, RenderState rs) {
- if(DEBUG_INSTANCE) {
- System.err.println("VBORegion2PES2 Destroy: " + this);
- }
- final ShaderState st = rs.getShaderState();
- if(null != fbo) {
- fbo.destroy(gl);
- fbo = null;
- texA = null;
- }
- if(null != verticeTxtAttr) {
- st.ownAttribute(verticeTxtAttr, false);
- verticeTxtAttr.destroy(gl);
- verticeTxtAttr = null;
- }
- if(null != texCoordTxtAttr) {
- st.ownAttribute(texCoordTxtAttr, false);
- texCoordTxtAttr.destroy(gl);
- texCoordTxtAttr = null;
- }
- if(null != indicesTxt) {
- indicesTxt.destroy(gl);
- indicesTxt = null;
- }
- if(null != verticeFboAttr) {
- st.ownAttribute(verticeFboAttr, false);
- verticeFboAttr.destroy(gl);
- verticeFboAttr = null;
- }
- if(null != texCoordFboAttr) {
- st.ownAttribute(texCoordFboAttr, false);
- texCoordFboAttr.destroy(gl);
- texCoordFboAttr = null;
- }
- if(null != indicesFbo) {
- indicesFbo.destroy(gl);
- indicesFbo = null;
- }
- triangles.clear();
- vertices.clear();
- }
-}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java
new file mode 100644
index 000000000..176b39c25
--- /dev/null
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java
@@ -0,0 +1,411 @@
+/**
+ * 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 java.nio.FloatBuffer;
+
+import javax.media.opengl.GL2ES2;
+// FIXME: Subsume GL2GL3.GL_DRAW_FRAMEBUFFER -> GL2ES2.GL_DRAW_FRAMEBUFFER !
+import javax.media.opengl.GL;
+import javax.media.opengl.GLUniformData;
+import javax.media.opengl.fixedfunc.GLMatrixFunc;
+
+import jogamp.graph.curve.opengl.shader.AttributeNames;
+import jogamp.graph.curve.opengl.shader.UniformNames;
+
+import com.jogamp.common.nio.Buffers;
+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.FBObject;
+import com.jogamp.opengl.FBObject.Attachment;
+import com.jogamp.opengl.math.geom.AABBox;
+import com.jogamp.opengl.util.GLArrayDataServer;
+import com.jogamp.opengl.util.PMVMatrix;
+import com.jogamp.opengl.util.glsl.ShaderState;
+
+public class VBORegion2PMSAAES2 extends GLRegion {
+ private static final boolean DEBUG_FBO_1 = false;
+ private static final boolean DEBUG_FBO_2 = false;
+ private GLArrayDataServer verticeTxtAttr;
+ private GLArrayDataServer texCoordTxtAttr;
+ private GLArrayDataServer indicesTxtBuffer;
+ private GLArrayDataServer verticeFboAttr;
+ private GLArrayDataServer texCoordFboAttr;
+ private GLArrayDataServer indicesFbo;
+
+ private FBObject fbo;
+ private final PMVMatrix fboPMVMatrix;
+ GLUniformData mgl_fboPMVMatrix;
+
+ private int fboWidth = 0;
+ private int fboHeight = 0;
+ GLUniformData mgl_ActiveTexture;
+ GLUniformData mgl_TextureSize;
+
+ final int[] maxTexSize = new int[] { -1 } ;
+
+ public VBORegion2PMSAAES2(final int renderModes, final int textureUnit) {
+ super(renderModes);
+ final int initialElementCount = 256;
+ fboPMVMatrix = new PMVMatrix();
+ mgl_fboPMVMatrix = new GLUniformData(UniformNames.gcu_PMVMatrix, 4, 4, fboPMVMatrix.glGetPMvMatrixf());
+ mgl_ActiveTexture = new GLUniformData(UniformNames.gcu_TextureUnit, textureUnit);
+
+ indicesTxtBuffer = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialElementCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
+ verticeTxtAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT,
+ false, initialElementCount, GL.GL_STATIC_DRAW);
+ texCoordTxtAttr = GLArrayDataServer.createGLSL(AttributeNames.TEXCOORD_ATTR_NAME, 2, GL2ES2.GL_FLOAT,
+ false, initialElementCount, GL.GL_STATIC_DRAW);
+ }
+
+ @Override
+ protected final void clearImpl(final GL2ES2 gl, final RegionRenderer renderer) {
+ indicesTxtBuffer.seal(gl, false);
+ indicesTxtBuffer.rewind();
+ verticeTxtAttr.seal(gl, false);
+ verticeTxtAttr.rewind();
+ texCoordTxtAttr.seal(gl, false);
+ texCoordTxtAttr.rewind();
+ }
+
+ @Override
+ protected final void pushVertex(float[] coords, float[] texParams) {
+ verticeTxtAttr.putf(coords[0]);
+ verticeTxtAttr.putf(coords[1]);
+ verticeTxtAttr.putf(coords[2]);
+
+ texCoordTxtAttr.putf(texParams[0]);
+ texCoordTxtAttr.putf(texParams[1]);
+ }
+
+ @Override
+ protected final void pushIndex(int idx) {
+ indicesTxtBuffer.puts((short)idx);
+ }
+
+ @Override
+ protected void update(final GL2ES2 gl, final RegionRenderer renderer) {
+ if(null == indicesFbo) {
+ final ShaderState st = renderer.getShaderState();
+
+ indicesFbo = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, 2, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
+ indicesFbo.puts((short) 0); indicesFbo.puts((short) 1); indicesFbo.puts((short) 3);
+ indicesFbo.puts((short) 1); indicesFbo.puts((short) 2); indicesFbo.puts((short) 3);
+ indicesFbo.seal(true);
+
+ texCoordFboAttr = GLArrayDataServer.createGLSL(AttributeNames.TEXCOORD_ATTR_NAME, 2, GL2ES2.GL_FLOAT,
+ false, 4, GL.GL_STATIC_DRAW);
+ st.ownAttribute(texCoordFboAttr, true);
+ texCoordFboAttr.putf(0); texCoordFboAttr.putf(0);
+ texCoordFboAttr.putf(0); texCoordFboAttr.putf(1);
+ texCoordFboAttr.putf(1); texCoordFboAttr.putf(1);
+ texCoordFboAttr.putf(1); texCoordFboAttr.putf(0);
+ texCoordFboAttr.seal(true);
+
+ verticeFboAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT,
+ false, 4, GL.GL_STATIC_DRAW);
+ st.ownAttribute(verticeFboAttr, true);
+
+ st.ownAttribute(verticeTxtAttr, true);
+ st.ownAttribute(texCoordTxtAttr, true);
+
+ if(Region.DEBUG_INSTANCE) {
+ System.err.println("VBORegion2PES2 Create: " + this);
+ }
+ }
+ // seal buffers
+ indicesTxtBuffer.seal(gl, true);
+ indicesTxtBuffer.enableBuffer(gl, false);
+ texCoordTxtAttr.seal(gl, true);
+ texCoordTxtAttr.enableBuffer(gl, false);
+ verticeTxtAttr.seal(gl, true);
+ verticeTxtAttr.enableBuffer(gl, false);
+
+ // update all bbox related data
+ verticeFboAttr.seal(gl, false);
+ verticeFboAttr.rewind();
+ verticeFboAttr.putf(box.getMinX()); verticeFboAttr.putf(box.getMinY()); verticeFboAttr.putf(box.getMinZ());
+ verticeFboAttr.putf(box.getMinX()); verticeFboAttr.putf(box.getMaxY()); verticeFboAttr.putf(box.getMinZ());
+ verticeFboAttr.putf(box.getMaxX()); verticeFboAttr.putf(box.getMaxY()); verticeFboAttr.putf(box.getMinZ());
+ verticeFboAttr.putf(box.getMaxX()); verticeFboAttr.putf(box.getMinY()); verticeFboAttr.putf(box.getMinZ());
+ verticeFboAttr.seal(gl, true);
+ verticeFboAttr.enableBuffer(gl, false);
+
+ fboPMVMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
+ fboPMVMatrix.glLoadIdentity();
+ fboPMVMatrix.glOrthof(box.getMinX(), box.getMaxX(), box.getMinY(), box.getMaxY(), -1, 1);
+
+ // push data 2 GPU ..
+ indicesFbo.seal(gl, true);
+ indicesFbo.enableBuffer(gl, false);
+
+ // trigger renderRegion2FBO !
+ fboHeight = 0;
+ fboWidth = 0;
+ // the buffers were disabled, since due to real/fbo switching and other vbo usage
+ }
+
+ private final AABBox drawWinBox = new AABBox();
+ private final int[] drawView = new int[] { 0, 0, 0, 0 };
+ private final float[] drawTmpV3 = new float[3];
+
+ @Override
+ protected void drawImpl(final GL2ES2 gl, final RegionRenderer renderer, final int[/*1*/] sampleCount) {
+ final int width = renderer.getWidth();
+ final int height = renderer.getHeight();
+ if(width <=0 || height <= 0 || null==sampleCount || sampleCount[0] <= 0){
+ renderRegion(gl);
+ } else {
+ if(0 > maxTexSize[0]) {
+ gl.glGetIntegerv(GL.GL_MAX_TEXTURE_SIZE, maxTexSize, 0);
+ }
+ final RenderState rs = renderer.getRenderState();
+ float renderFboWidth, renderFboHeight;
+ int targetFboWidth, targetFboHeight;
+ float diffWidth, diffHeight;
+ {
+ // Calculate perspective pixel width/height for FBO,
+ // considering the sampleCount.
+ drawView[2] = width;
+ drawView[3] = height;
+ box.mapToWindow(drawWinBox, renderer.getMatrix(), drawView, true /* useCenterZ */, drawTmpV3);
+ renderFboWidth = drawWinBox.getWidth();
+ renderFboHeight = drawWinBox.getHeight();
+ targetFboWidth = (int)Math.ceil(renderFboWidth);
+ targetFboHeight = (int)Math.ceil(renderFboHeight);
+ diffWidth = targetFboWidth-renderFboWidth;
+ diffHeight = targetFboHeight-renderFboHeight;
+ if( DEBUG_FBO_2 ) {
+ System.err.printf("XXX.MinMax view[%d, %d]: FBO f[%.3f, %.3f], i[%d x %d], d[%.3f, %.3f], msaa %d%n",
+ drawView[2], drawView[3],
+ renderFboWidth, renderFboHeight, targetFboWidth, targetFboHeight,
+ diffWidth, diffHeight, sampleCount[0]);
+ }
+ }
+ final int deltaFboWidth = Math.abs(targetFboWidth-fboWidth);
+ final int deltaFboHeight = Math.abs(targetFboHeight-fboHeight);
+ final int maxDeltaFbo, maxLengthFbo;
+ if( deltaFboWidth >= deltaFboHeight ) {
+ maxDeltaFbo = deltaFboWidth;
+ maxLengthFbo = fboWidth > 0 ? fboWidth : 1;
+ } else {
+ maxDeltaFbo = deltaFboHeight;
+ maxLengthFbo = fboHeight > 0 ? fboHeight : 1;
+ }
+ final float pctFboDelta = (float)maxDeltaFbo / (float)maxLengthFbo;
+ if( DEBUG_FBO_2 ) {
+ System.err.printf("XXX.maxDelta: %d / %d = %.3f%n", maxDeltaFbo, maxLengthFbo, pctFboDelta);
+ }
+ if( pctFboDelta > 0.1f || ( fbo != null && fbo.getNumSamples() != sampleCount[0] ) ) { // more than 10% !
+ if( DEBUG_FBO_1 ) {
+ System.err.printf("XXX.maxDelta: %d / %d = %.3f%n", maxDeltaFbo, maxLengthFbo, pctFboDelta);
+ System.err.printf("XXX.MSAA %d, %d x %d%n",
+ sampleCount[0], targetFboWidth, targetFboHeight);
+ }
+ // FIXME: maxTexSize test not correct
+ boolean rescale = false;
+ if( targetFboWidth > maxTexSize[0] ) {
+ targetFboWidth = maxTexSize[0];
+ renderFboWidth = targetFboWidth;
+ rescale = true;
+ }
+ if( targetFboHeight > maxTexSize[0] ) {
+ targetFboHeight = maxTexSize[0];
+ renderFboHeight = targetFboHeight;
+ rescale = true;
+ }
+ if(rescale) {
+ diffWidth = targetFboWidth-renderFboWidth;
+ diffHeight = targetFboHeight-renderFboHeight;
+ if( DEBUG_FBO_1 ) {
+ System.err.printf("XXX.Rescale (MAX): FBO f[%.3f, %.3f], i[%d x %d], d[%.3f, %.3f], msaa %d%n",
+ renderFboWidth, renderFboHeight, targetFboWidth, targetFboHeight,
+ diffWidth, diffHeight, sampleCount[0]);
+ }
+ }
+ verticeFboAttr.seal(false);
+ verticeFboAttr.rewind();
+ verticeFboAttr.putf(box.getMinX()); verticeFboAttr.putf(box.getMinY()); verticeFboAttr.putf(box.getMinZ());
+ verticeFboAttr.putf(box.getMinX()); verticeFboAttr.putf(box.getMaxY()+diffHeight); verticeFboAttr.putf(box.getMinZ());
+ verticeFboAttr.putf(box.getMaxX()+diffWidth); verticeFboAttr.putf(box.getMaxY()+diffHeight); verticeFboAttr.putf(box.getMinZ());
+ verticeFboAttr.putf(box.getMaxX()+diffWidth); verticeFboAttr.putf(box.getMinY()); verticeFboAttr.putf(box.getMinZ());
+ verticeFboAttr.seal(true);
+ fboPMVMatrix.glLoadIdentity();
+ fboPMVMatrix.glOrthof(box.getMinX(), box.getMaxX()+diffWidth,
+ box.getMinY(), box.getMaxY()+diffHeight, -1, 1);
+ renderRegion2FBO(gl, rs, targetFboWidth, targetFboHeight, sampleCount);
+ } else {
+ texCoordFboAttr.setVBOWritten(false);
+ }
+ // System.out.println("Scale: " + matrix.glGetMatrixf().get(1+4*3) +" " + matrix.glGetMatrixf().get(2+4*3));
+ renderFBO(gl, rs, width, height);
+ }
+ }
+ private void setTexSize(final GL2ES2 gl, final ShaderState st, boolean firstPass) {
+ if(null == mgl_TextureSize) {
+ mgl_TextureSize = new GLUniformData(UniformNames.gcu_TextureSize, 3, Buffers.newDirectFloatBuffer(3));
+ }
+ final FloatBuffer texSize = (FloatBuffer) mgl_TextureSize.getBuffer();
+ if( firstPass ) {
+ texSize.put(2, 0f);
+ } else {
+ texSize.put(0, fboWidth);
+ texSize.put(1, fboHeight);
+ texSize.put(2, 1f);
+ }
+ st.uniform(gl, mgl_TextureSize);
+ }
+
+ private void renderFBO(final GL2ES2 gl, final RenderState rs, final int width, final int height) {
+ final ShaderState st = rs.getShaderState();
+
+ gl.glViewport(0, 0, width, height);
+ st.uniform(gl, mgl_ActiveTexture);
+ gl.glActiveTexture(GL.GL_TEXTURE0 + mgl_ActiveTexture.intValue());
+ setTexSize(gl, st, false);
+
+ fbo.use(gl, fbo.getSamplingSink());
+ verticeFboAttr.enableBuffer(gl, true);
+ texCoordFboAttr.enableBuffer(gl, true);
+ indicesFbo.bindBuffer(gl, true); // keeps VBO binding
+
+ gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesFbo.getElementCount() * indicesFbo.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0);
+
+ indicesFbo.bindBuffer(gl, false);
+ texCoordFboAttr.enableBuffer(gl, false);
+ verticeFboAttr.enableBuffer(gl, false);
+ fbo.unuse(gl);
+
+ // setback: gl.glActiveTexture(currentActiveTextureEngine[0]);
+ }
+
+ private void renderRegion2FBO(final GL2ES2 gl, final RenderState rs, final int targetFboWidth, final int targetFboHeight, int[] sampleCount) {
+ final ShaderState st = rs.getShaderState();
+
+ if( 0 >= targetFboWidth || 0 >= targetFboHeight ) {
+ throw new IllegalArgumentException("fboSize must be greater than 0: "+targetFboWidth+"x"+targetFboHeight);
+ }
+
+ if(null == fbo) {
+ fboWidth = targetFboWidth;
+ fboHeight = targetFboHeight;
+ fbo = new FBObject();
+ fbo.reset(gl, fboWidth, fboHeight, sampleCount[0], false);
+ sampleCount[0] = fbo.getNumSamples();
+ fbo.attachColorbuffer(gl, 0, true);
+ fbo.attachRenderbuffer(gl, Attachment.Type.DEPTH, 24);
+ final FBObject ssink = new FBObject();
+ {
+ ssink.reset(gl, fboWidth, fboHeight);
+ // FIXME: shall not use bilinear (GL_LINEAR), due to MSAA ???
+ // ssink.attachTexture2D(gl, 0, true, GL2ES2.GL_LINEAR, GL2ES2.GL_LINEAR, GL2ES2.GL_CLAMP_TO_EDGE, GL2ES2.GL_CLAMP_TO_EDGE);
+ ssink.attachTexture2D(gl, 0, true, GL2ES2.GL_NEAREST, GL2ES2.GL_NEAREST, GL2ES2.GL_CLAMP_TO_EDGE, GL2ES2.GL_CLAMP_TO_EDGE);
+ ssink.attachRenderbuffer(gl, Attachment.Type.DEPTH, 24);
+ }
+ fbo.setSamplingSink(ssink);
+ fbo.resetSamplingSink(gl); // validate
+ if( DEBUG_FBO_1 ) {
+ System.err.printf("XXX.createFBO: %dx%d%n%s%n", fboWidth, fboHeight, fbo.toString());
+ }
+ } else if( targetFboWidth != fboWidth || targetFboHeight != fboHeight || fbo.getNumSamples() != sampleCount[0] ) {
+ fbo.reset(gl, targetFboWidth, targetFboHeight, sampleCount[0], true /* resetSamplingSink */);
+ sampleCount[0] = fbo.getNumSamples();
+ if( DEBUG_FBO_1 ) {
+ System.err.printf("XXX.resetFBO: %dx%d -> %dx%d%n%s%n", fboWidth, fboHeight, targetFboWidth, targetFboHeight, fbo );
+ }
+ fboWidth = targetFboWidth;
+ fboHeight = targetFboHeight;
+ }
+ fbo.bind(gl);
+ setTexSize(gl, st, true);
+
+ //render texture
+ gl.glViewport(0, 0, fboWidth, fboHeight);
+ st.uniform(gl, mgl_fboPMVMatrix); // use orthogonal matrix
+
+ gl.glClear(GL2ES2.GL_COLOR_BUFFER_BIT | GL2ES2.GL_DEPTH_BUFFER_BIT);
+ renderRegion(gl);
+ fbo.unbind(gl);
+
+ st.uniform(gl, rs.getPMVMatrix()); // switch back to real PMV matrix
+ }
+
+ private void renderRegion(final GL2ES2 gl) {
+ verticeTxtAttr.enableBuffer(gl, true);
+ texCoordTxtAttr.enableBuffer(gl, true);
+ indicesTxtBuffer.bindBuffer(gl, true); // keeps VBO binding
+
+ gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesTxtBuffer.getElementCount() * indicesTxtBuffer.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0);
+
+ indicesTxtBuffer.bindBuffer(gl, false);
+ texCoordTxtAttr.enableBuffer(gl, false);
+ verticeTxtAttr.enableBuffer(gl, false);
+ }
+
+ @Override
+ protected void destroyImpl(final GL2ES2 gl, final RegionRenderer renderer) {
+ if(DEBUG_INSTANCE) {
+ System.err.println("VBORegion2PES2 Destroy: " + this);
+ }
+ final ShaderState st = renderer.getShaderState();
+ if(null != fbo) {
+ fbo.destroy(gl);
+ fbo = null;
+ }
+ if(null != verticeTxtAttr) {
+ st.ownAttribute(verticeTxtAttr, false);
+ verticeTxtAttr.destroy(gl);
+ verticeTxtAttr = null;
+ }
+ if(null != texCoordTxtAttr) {
+ st.ownAttribute(texCoordTxtAttr, false);
+ texCoordTxtAttr.destroy(gl);
+ texCoordTxtAttr = null;
+ }
+ if(null != indicesTxtBuffer) {
+ indicesTxtBuffer.destroy(gl);
+ indicesTxtBuffer = null;
+ }
+ if(null != verticeFboAttr) {
+ st.ownAttribute(verticeFboAttr, false);
+ verticeFboAttr.destroy(gl);
+ verticeFboAttr = null;
+ }
+ if(null != texCoordFboAttr) {
+ st.ownAttribute(texCoordFboAttr, false);
+ texCoordFboAttr.destroy(gl);
+ texCoordFboAttr = null;
+ }
+ if(null != indicesFbo) {
+ indicesFbo.destroy(gl);
+ indicesFbo = null;
+ }
+ }
+}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java
new file mode 100644
index 000000000..3f3709d6e
--- /dev/null
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java
@@ -0,0 +1,408 @@
+/**
+ * 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 java.nio.FloatBuffer;
+
+import javax.media.opengl.GL2ES2;
+import javax.media.opengl.GL;
+import javax.media.opengl.GLUniformData;
+import javax.media.opengl.fixedfunc.GLMatrixFunc;
+
+import jogamp.graph.curve.opengl.shader.AttributeNames;
+import jogamp.graph.curve.opengl.shader.UniformNames;
+
+import com.jogamp.common.nio.Buffers;
+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.FBObject;
+import com.jogamp.opengl.FBObject.Attachment;
+import com.jogamp.opengl.FBObject.TextureAttachment;
+import com.jogamp.opengl.math.geom.AABBox;
+import com.jogamp.opengl.util.GLArrayDataServer;
+import com.jogamp.opengl.util.PMVMatrix;
+import com.jogamp.opengl.util.glsl.ShaderState;
+
+public class VBORegion2PVBAAES2 extends GLRegion {
+ private static final boolean DEBUG_FBO_1 = false;
+ private static final boolean DEBUG_FBO_2 = false;
+ private GLArrayDataServer verticeTxtAttr;
+ private GLArrayDataServer texCoordTxtAttr;
+ private GLArrayDataServer indicesTxtBuffer;
+ private GLArrayDataServer verticeFboAttr;
+ private GLArrayDataServer texCoordFboAttr;
+ private GLArrayDataServer indicesFbo;
+
+ private FBObject fbo;
+ private TextureAttachment texA;
+ private final PMVMatrix fboPMVMatrix;
+ GLUniformData mgl_fboPMVMatrix;
+
+ private int fboWidth = 0;
+ private int fboHeight = 0;
+ GLUniformData mgl_ActiveTexture;
+ GLUniformData mgl_TextureSize;
+
+ final int[] maxTexSize = new int[] { -1 } ;
+
+ public VBORegion2PVBAAES2(final int renderModes, final int textureUnit) {
+ super(renderModes);
+ final int initialElementCount = 256;
+ fboPMVMatrix = new PMVMatrix();
+ mgl_fboPMVMatrix = new GLUniformData(UniformNames.gcu_PMVMatrix, 4, 4, fboPMVMatrix.glGetPMvMatrixf());
+ mgl_ActiveTexture = new GLUniformData(UniformNames.gcu_TextureUnit, textureUnit);
+
+ indicesTxtBuffer = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialElementCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
+ verticeTxtAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT,
+ false, initialElementCount, GL.GL_STATIC_DRAW);
+ texCoordTxtAttr = GLArrayDataServer.createGLSL(AttributeNames.TEXCOORD_ATTR_NAME, 2, GL2ES2.GL_FLOAT,
+ false, initialElementCount, GL.GL_STATIC_DRAW);
+ }
+
+ @Override
+ protected final void clearImpl(final GL2ES2 gl, final RegionRenderer renderer) {
+ indicesTxtBuffer.seal(gl, false);
+ indicesTxtBuffer.rewind();
+ verticeTxtAttr.seal(gl, false);
+ verticeTxtAttr.rewind();
+ texCoordTxtAttr.seal(gl, false);
+ texCoordTxtAttr.rewind();
+ }
+
+ @Override
+ protected final void pushVertex(float[] coords, float[] texParams) {
+ verticeTxtAttr.putf(coords[0]);
+ verticeTxtAttr.putf(coords[1]);
+ verticeTxtAttr.putf(coords[2]);
+
+ texCoordTxtAttr.putf(texParams[0]);
+ texCoordTxtAttr.putf(texParams[1]);
+ }
+
+ @Override
+ protected final void pushIndex(int idx) {
+ indicesTxtBuffer.puts((short)idx);
+ }
+
+ @Override
+ protected void update(final GL2ES2 gl, final RegionRenderer renderer) {
+ if(null == indicesFbo) {
+ final ShaderState st = renderer.getShaderState();
+
+ indicesFbo = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, 2, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
+ indicesFbo.puts((short) 0); indicesFbo.puts((short) 1); indicesFbo.puts((short) 3);
+ indicesFbo.puts((short) 1); indicesFbo.puts((short) 2); indicesFbo.puts((short) 3);
+ indicesFbo.seal(true);
+
+ texCoordFboAttr = GLArrayDataServer.createGLSL(AttributeNames.TEXCOORD_ATTR_NAME, 2, GL2ES2.GL_FLOAT,
+ false, 4, GL.GL_STATIC_DRAW);
+ st.ownAttribute(texCoordFboAttr, true);
+ texCoordFboAttr.putf(0); texCoordFboAttr.putf(0);
+ texCoordFboAttr.putf(0); texCoordFboAttr.putf(1);
+ texCoordFboAttr.putf(1); texCoordFboAttr.putf(1);
+ texCoordFboAttr.putf(1); texCoordFboAttr.putf(0);
+ texCoordFboAttr.seal(true);
+
+ verticeFboAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT,
+ false, 4, GL.GL_STATIC_DRAW);
+ st.ownAttribute(verticeFboAttr, true);
+
+ st.ownAttribute(verticeTxtAttr, true);
+ st.ownAttribute(texCoordTxtAttr, true);
+
+ if(Region.DEBUG_INSTANCE) {
+ System.err.println("VBORegion2PES2 Create: " + this);
+ }
+ }
+ // seal buffers
+ indicesTxtBuffer.seal(gl, true);
+ indicesTxtBuffer.enableBuffer(gl, false);
+ texCoordTxtAttr.seal(gl, true);
+ texCoordTxtAttr.enableBuffer(gl, false);
+ verticeTxtAttr.seal(gl, true);
+ verticeTxtAttr.enableBuffer(gl, false);
+
+ // update all bbox related data
+ verticeFboAttr.seal(gl, false);
+ verticeFboAttr.rewind();
+ verticeFboAttr.putf(box.getMinX()); verticeFboAttr.putf(box.getMinY()); verticeFboAttr.putf(box.getMinZ());
+ verticeFboAttr.putf(box.getMinX()); verticeFboAttr.putf(box.getMaxY()); verticeFboAttr.putf(box.getMinZ());
+ verticeFboAttr.putf(box.getMaxX()); verticeFboAttr.putf(box.getMaxY()); verticeFboAttr.putf(box.getMinZ());
+ verticeFboAttr.putf(box.getMaxX()); verticeFboAttr.putf(box.getMinY()); verticeFboAttr.putf(box.getMinZ());
+ verticeFboAttr.seal(gl, true);
+ verticeFboAttr.enableBuffer(gl, false);
+
+ fboPMVMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
+ fboPMVMatrix.glLoadIdentity();
+ fboPMVMatrix.glOrthof(box.getMinX(), box.getMaxX(), box.getMinY(), box.getMaxY(), -1, 1);
+
+ // push data 2 GPU ..
+ indicesFbo.seal(gl, true);
+ indicesFbo.enableBuffer(gl, false);
+
+ // trigger renderRegion2FBO !
+ fboHeight = 0;
+ fboWidth = 0;
+ // the buffers were disabled, since due to real/fbo switching and other vbo usage
+ }
+
+ private final AABBox drawWinBox = new AABBox();
+ private final int[] drawView = new int[] { 0, 0, 0, 0 };
+ private final float[] drawTmpV3 = new float[3];
+
+ @Override
+ protected void drawImpl(final GL2ES2 gl, final RegionRenderer renderer, final int[/*1*/] sampleCount) {
+ final int width = renderer.getWidth();
+ final int height = renderer.getHeight();
+ if(width <=0 || height <= 0 || null==sampleCount || sampleCount[0] <= 0){
+ renderRegion(gl);
+ } else {
+ if(0 > maxTexSize[0]) {
+ gl.glGetIntegerv(GL.GL_MAX_TEXTURE_SIZE, maxTexSize, 0);
+ }
+ final RenderState rs = renderer.getRenderState();
+ final float winWidth, winHeight;
+ int targetFboWidth, targetFboHeight;
+ float renderFboWidth, renderFboHeight;
+ float diffWidth, diffHeight;
+ {
+ // Calculate perspective pixel width/height for FBO,
+ // considering the sampleCount.
+ drawView[2] = width;
+ drawView[3] = height;
+ box.mapToWindow(drawWinBox, renderer.getMatrix(), drawView, true /* useCenterZ */, drawTmpV3);
+ winWidth = drawWinBox.getWidth();
+ winHeight = drawWinBox.getHeight();
+ diffWidth = (float)Math.ceil(winWidth)-winWidth;
+ diffHeight = (float)Math.ceil(winHeight)-winHeight;
+ renderFboWidth = winWidth*sampleCount[0];
+ renderFboHeight = winHeight*sampleCount[0];
+ targetFboWidth = (int)Math.ceil(renderFboWidth);
+ targetFboHeight = (int)Math.ceil(renderFboHeight);
+ if( DEBUG_FBO_2 ) {
+ System.err.printf("XXX.MinMax1 view[%d, %d] -> win[%.3f, %.3f]: FBO f[%.3f, %.3f], i[%d x %d], d[%.3f, %.3f], msaa %d%n",
+ drawView[2], drawView[3],
+ winWidth, winHeight,
+ renderFboWidth, renderFboHeight, targetFboWidth, targetFboHeight,
+ diffWidth, diffHeight, sampleCount[0]);
+ }
+ }
+ final int deltaFboWidth = Math.abs(targetFboWidth-fboWidth);
+ final int deltaFboHeight = Math.abs(targetFboHeight-fboHeight);
+ final int maxDeltaFbo, maxLengthFbo;
+ if( deltaFboWidth >= deltaFboHeight ) {
+ maxDeltaFbo = deltaFboWidth;
+ maxLengthFbo = fboWidth > 0 ? fboWidth : 1;
+ } else {
+ maxDeltaFbo = deltaFboHeight;
+ maxLengthFbo = fboHeight > 0 ? fboHeight : 1;
+ }
+ final float pctFboDelta = (float)maxDeltaFbo / (float)maxLengthFbo;
+ if( DEBUG_FBO_2 ) {
+ System.err.printf("XXX.maxDelta: %d / %d = %.3f%n", maxDeltaFbo, maxLengthFbo, pctFboDelta);
+ }
+ if( pctFboDelta > 0.1f ) { // more than 10% !
+ if( DEBUG_FBO_1 ) {
+ System.err.printf("XXX.maxDelta: %d / %d = %.3f%n", maxDeltaFbo, maxLengthFbo, pctFboDelta);
+ System.err.printf("XXX.Scale %d * [%f x %f]: %d x %d%n",
+ sampleCount[0], winWidth, winHeight, targetFboWidth, targetFboHeight);
+ }
+ final int maxLength = Math.max(targetFboWidth, targetFboHeight);
+ if( maxLength > maxTexSize[0] ) {
+ if( targetFboWidth > targetFboHeight ) {
+ sampleCount[0] = (int)Math.floor(maxTexSize[0] / winWidth);
+ } else {
+ sampleCount[0] = (int)Math.floor(maxTexSize[0] / winHeight);
+ }
+ renderFboWidth = winWidth*sampleCount[0];
+ renderFboHeight = winHeight*sampleCount[0];
+ targetFboWidth = (int)Math.ceil(renderFboWidth);
+ targetFboHeight = (int)Math.ceil(renderFboHeight);
+ if( DEBUG_FBO_1 ) {
+ System.err.printf("XXX.Rescale (MAX): win[%.3f, %.3f]: FBO f[%.3f, %.3f], i[%d x %d], msaa %d%n",
+ winWidth, winHeight,
+ renderFboWidth, renderFboHeight, targetFboWidth, targetFboHeight, sampleCount[0]);
+ }
+ if( sampleCount[0] <= 0 ) {
+ // Last way out!
+ renderRegion(gl);
+ return;
+ }
+ }
+ verticeFboAttr.seal(false);
+ verticeFboAttr.rewind();
+ verticeFboAttr.putf(box.getMinX()); verticeFboAttr.putf(box.getMinY()); verticeFboAttr.putf(box.getMinZ());
+ verticeFboAttr.putf(box.getMinX()); verticeFboAttr.putf(box.getMaxY()+diffHeight); verticeFboAttr.putf(box.getMinZ());
+ verticeFboAttr.putf(box.getMaxX()+diffWidth); verticeFboAttr.putf(box.getMaxY()+diffHeight); verticeFboAttr.putf(box.getMinZ());
+ verticeFboAttr.putf(box.getMaxX()+diffWidth); verticeFboAttr.putf(box.getMinY()); verticeFboAttr.putf(box.getMinZ());
+ verticeFboAttr.seal(true);
+ fboPMVMatrix.glLoadIdentity();
+ fboPMVMatrix.glOrthof(box.getMinX(), box.getMaxX()+diffWidth,
+ box.getMinY(), box.getMaxY()+diffHeight, -1, 1);
+ renderRegion2FBO(gl, rs, targetFboWidth, targetFboHeight, sampleCount[0]);
+ }
+ // System.out.println("Scale: " + matrix.glGetMatrixf().get(1+4*3) +" " + matrix.glGetMatrixf().get(2+4*3));
+ renderFBO(gl, rs, width, height, sampleCount[0]);
+ }
+ }
+ private void setTexSize(final GL2ES2 gl, final ShaderState st, boolean firstPass, int sampleCount) {
+ if(null == mgl_TextureSize) {
+ mgl_TextureSize = new GLUniformData(UniformNames.gcu_TextureSize, 3, Buffers.newDirectFloatBuffer(3));
+ }
+ final FloatBuffer texSize = (FloatBuffer) mgl_TextureSize.getBuffer();
+ if( firstPass ) {
+ texSize.put(2, 0f);
+ } else {
+ texSize.put(0, fboWidth);
+ texSize.put(1, fboHeight);
+ texSize.put(2, sampleCount);
+ }
+ st.uniform(gl, mgl_TextureSize);
+ }
+
+ private void renderFBO(final GL2ES2 gl, final RenderState rs, final int width, final int height, int sampleCount) {
+ final ShaderState st = rs.getShaderState();
+
+ gl.glViewport(0, 0, width, height);
+ st.uniform(gl, mgl_ActiveTexture);
+ gl.glActiveTexture(GL.GL_TEXTURE0 + mgl_ActiveTexture.intValue());
+ setTexSize(gl, st, false, sampleCount);
+
+ fbo.use(gl, texA);
+ verticeFboAttr.enableBuffer(gl, true);
+ texCoordFboAttr.enableBuffer(gl, true);
+ indicesFbo.bindBuffer(gl, true); // keeps VBO binding
+
+ gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesFbo.getElementCount() * indicesFbo.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0);
+
+ indicesFbo.bindBuffer(gl, false);
+ texCoordFboAttr.enableBuffer(gl, false);
+ verticeFboAttr.enableBuffer(gl, false);
+ fbo.unuse(gl);
+
+ // setback: gl.glActiveTexture(currentActiveTextureEngine[0]);
+ }
+
+ private void renderRegion2FBO(final GL2ES2 gl, final RenderState rs, final int targetFboWidth, final int targetFboHeight, int sampleCount) {
+ final ShaderState st = rs.getShaderState();
+
+ if( 0 >= targetFboWidth || 0 >= targetFboHeight ) {
+ throw new IllegalArgumentException("fboSize must be greater than 0: "+targetFboWidth+"x"+targetFboHeight);
+ }
+
+ if(null == fbo) {
+ fboWidth = targetFboWidth;
+ fboHeight = targetFboHeight;
+ fbo = new FBObject();
+ fbo.reset(gl, fboWidth, fboHeight);
+ // Shall not use bilinear (GL_LINEAR), due to own VBAA. Result is smooth w/o it now!
+ // texA = fbo.attachTexture2D(gl, 0, true, GL2ES2.GL_LINEAR, GL2ES2.GL_LINEAR, GL2ES2.GL_CLAMP_TO_EDGE, GL2ES2.GL_CLAMP_TO_EDGE);
+ texA = fbo.attachTexture2D(gl, 0, true, GL2ES2.GL_NEAREST, GL2ES2.GL_NEAREST, GL2ES2.GL_CLAMP_TO_EDGE, GL2ES2.GL_CLAMP_TO_EDGE);
+ fbo.attachRenderbuffer(gl, Attachment.Type.DEPTH, 24);
+ if( DEBUG_FBO_1 ) {
+ System.err.printf("XXX.createFBO: %dx%d%n%s%n", fboWidth, fboHeight, fbo.toString());
+ }
+ } else if( targetFboWidth != fboWidth || targetFboHeight != fboHeight ) {
+ fbo.reset(gl, targetFboWidth, targetFboHeight);
+ fbo.bind(gl);
+ if( DEBUG_FBO_1 ) {
+ System.err.printf("XXX.resetFBO: %dx%d -> %dx%d%n%s%n", fboWidth, fboHeight, targetFboWidth, targetFboHeight, fbo );
+ }
+ fboWidth = targetFboWidth;
+ fboHeight = targetFboHeight;
+ } else {
+ fbo.bind(gl);
+ }
+ setTexSize(gl, st, true, sampleCount);
+
+ //render texture
+ gl.glViewport(0, 0, fboWidth, fboHeight);
+ st.uniform(gl, mgl_fboPMVMatrix); // use orthogonal matrix
+
+ gl.glClear(GL2ES2.GL_COLOR_BUFFER_BIT | GL2ES2.GL_DEPTH_BUFFER_BIT);
+ renderRegion(gl);
+ fbo.unbind(gl);
+
+ st.uniform(gl, rs.getPMVMatrix()); // switch back to real PMV matrix
+ }
+
+ private void renderRegion(final GL2ES2 gl) {
+ verticeTxtAttr.enableBuffer(gl, true);
+ texCoordTxtAttr.enableBuffer(gl, true);
+ indicesTxtBuffer.bindBuffer(gl, true); // keeps VBO binding
+
+ gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesTxtBuffer.getElementCount() * indicesTxtBuffer.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0);
+
+ indicesTxtBuffer.bindBuffer(gl, false);
+ texCoordTxtAttr.enableBuffer(gl, false);
+ verticeTxtAttr.enableBuffer(gl, false);
+ }
+
+ @Override
+ protected void destroyImpl(final GL2ES2 gl, final RegionRenderer renderer) {
+ if(DEBUG_INSTANCE) {
+ System.err.println("VBORegion2PES2 Destroy: " + this);
+ }
+ final ShaderState st = renderer.getShaderState();
+ if(null != fbo) {
+ fbo.destroy(gl);
+ fbo = null;
+ texA = null;
+ }
+ if(null != verticeTxtAttr) {
+ st.ownAttribute(verticeTxtAttr, false);
+ verticeTxtAttr.destroy(gl);
+ verticeTxtAttr = null;
+ }
+ if(null != texCoordTxtAttr) {
+ st.ownAttribute(texCoordTxtAttr, false);
+ texCoordTxtAttr.destroy(gl);
+ texCoordTxtAttr = null;
+ }
+ if(null != indicesTxtBuffer) {
+ indicesTxtBuffer.destroy(gl);
+ indicesTxtBuffer = null;
+ }
+ if(null != verticeFboAttr) {
+ st.ownAttribute(verticeFboAttr, false);
+ verticeFboAttr.destroy(gl);
+ verticeFboAttr = null;
+ }
+ if(null != texCoordFboAttr) {
+ st.ownAttribute(texCoordFboAttr, false);
+ texCoordFboAttr.destroy(gl);
+ texCoordFboAttr = null;
+ }
+ if(null != indicesFbo) {
+ indicesFbo.destroy(gl);
+ indicesFbo = null;
+ }
+ }
+}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
index 9feb18a12..bdf824b6a 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
@@ -33,118 +33,94 @@ import javax.media.opengl.GL2ES2;
import jogamp.graph.curve.opengl.shader.AttributeNames;
import com.jogamp.graph.curve.opengl.GLRegion;
-import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.graph.geom.Vertex;
-import com.jogamp.graph.geom.Triangle;
+import com.jogamp.graph.curve.opengl.RegionRenderer;
import com.jogamp.opengl.util.GLArrayDataServer;
import com.jogamp.opengl.util.glsl.ShaderState;
public class VBORegionSPES2 extends GLRegion {
private GLArrayDataServer verticeAttr = null;
private GLArrayDataServer texCoordAttr = null;
- private GLArrayDataServer indices = null;
+ private GLArrayDataServer indicesBuffer = null;
+ private boolean buffersAttached = false;
- protected VBORegionSPES2(int renderModes) {
+ public VBORegionSPES2(final int renderModes) {
super(renderModes);
+ final int initialElementCount = 256;
+ indicesBuffer = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialElementCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
+
+ verticeAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT,
+ false, initialElementCount, GL.GL_STATIC_DRAW);
+
+ texCoordAttr = GLArrayDataServer.createGLSL(AttributeNames.TEXCOORD_ATTR_NAME, 2, GL2ES2.GL_FLOAT,
+ false, initialElementCount, GL.GL_STATIC_DRAW);
}
@Override
- protected void update(GL2ES2 gl, RenderState rs) {
- if(!isDirty()) {
- return;
- }
+ protected final void clearImpl(final GL2ES2 gl, final RegionRenderer renderer) {
+ indicesBuffer.seal(gl, false);
+ indicesBuffer.rewind();
+ verticeAttr.seal(gl, false);
+ verticeAttr.rewind();
+ texCoordAttr.seal(gl, false);
+ texCoordAttr.rewind();
+ }
- if(null == indices) {
- final int initialElementCount = 256;
- final ShaderState st = rs.getShaderState();
+ @Override
+ protected final void pushVertex(float[] coords, float[] texParams) {
+ verticeAttr.putf(coords[0]);
+ verticeAttr.putf(coords[1]);
+ verticeAttr.putf(coords[2]);
- indices = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialElementCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
+ texCoordAttr.putf(texParams[0]);
+ texCoordAttr.putf(texParams[1]);
+ }
- verticeAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT,
- false, initialElementCount, GL.GL_STATIC_DRAW);
- st.ownAttribute(verticeAttr, true);
+ @Override
+ protected final void pushIndex(int idx) {
+ indicesBuffer.puts((short)idx);
+ }
- texCoordAttr = GLArrayDataServer.createGLSL(AttributeNames.TEXCOORD_ATTR_NAME, 2, GL2ES2.GL_FLOAT,
- false, initialElementCount, GL.GL_STATIC_DRAW);
+ @Override
+ protected void update(final GL2ES2 gl, final RegionRenderer renderer) {
+ if( !buffersAttached ) {
+ final ShaderState st = renderer.getShaderState();
+ st.ownAttribute(verticeAttr, true);
st.ownAttribute(texCoordAttr, true);
-
- if(DEBUG_INSTANCE) {
- System.err.println("VBORegionSPES2 Create: " + this);
- }
- }
-
- // process triangles
- indices.seal(gl, false);
- indices.rewind();
- for(int i=0; i<triangles.size(); i++) {
- final Triangle t = triangles.get(i);
- final Vertex[] t_vertices = t.getVertices();
-
- if(t_vertices[0].getId() == Integer.MAX_VALUE){
- t_vertices[0].setId(numVertices++);
- t_vertices[1].setId(numVertices++);
- t_vertices[2].setId(numVertices++);
-
- vertices.add(t_vertices[0]);
- vertices.add(t_vertices[1]);
- vertices.add(t_vertices[2]);
-
- indices.puts((short) t_vertices[0].getId());
- indices.puts((short) t_vertices[1].getId());
- indices.puts((short) t_vertices[2].getId());
- } else {
- indices.puts((short) t_vertices[0].getId());
- indices.puts((short) t_vertices[1].getId());
- indices.puts((short) t_vertices[2].getId());
- }
- }
- indices.seal(gl, true);
- indices.enableBuffer(gl, false);
-
- // process vertices and update bbox
- box.reset();
- verticeAttr.seal(gl, false);
- verticeAttr.rewind();
- texCoordAttr.seal(gl, false);
- texCoordAttr.rewind();
- for(int i=0; i<vertices.size(); i++) {
- final Vertex v = vertices.get(i);
- verticeAttr.putf(v.getX());
- verticeAttr.putf(v.getY());
- verticeAttr.putf(v.getZ());
- box.resize(v.getX(), v.getY(), v.getZ());
-
- final float[] tex = v.getTexCoord();
- texCoordAttr.putf(tex[0]);
- texCoordAttr.putf(tex[1]);
+ buffersAttached = true;
}
+ // seal buffers
+ indicesBuffer.seal(gl, true);
+ indicesBuffer.enableBuffer(gl, false);
verticeAttr.seal(gl, true);
verticeAttr.enableBuffer(gl, false);
texCoordAttr.seal(gl, true);
texCoordAttr.enableBuffer(gl, false);
-
- setDirty(false);
+ if(DEBUG_INSTANCE) {
+ System.err.println("VBORegionSPES2 idx "+indicesBuffer);
+ System.err.println("VBORegionSPES2 ver "+verticeAttr);
+ System.err.println("VBORegionSPES2 tex "+texCoordAttr);
+ }
}
@Override
- protected void drawImpl(GL2ES2 gl, RenderState rs, int vp_width, int vp_height, int[/*1*/] texWidth) {
+ protected void drawImpl(final GL2ES2 gl, final RegionRenderer renderer, final int[/*1*/] sampleCount) {
verticeAttr.enableBuffer(gl, true);
texCoordAttr.enableBuffer(gl, true);
- indices.bindBuffer(gl, true); // keeps VBO binding
+ indicesBuffer.bindBuffer(gl, true); // keeps VBO binding
- gl.glDrawElements(GL2ES2.GL_TRIANGLES, indices.getElementCount() * indices.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0);
+ gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesBuffer.getElementCount() * indicesBuffer.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0);
- indices.bindBuffer(gl, false);
+ indicesBuffer.bindBuffer(gl, false);
texCoordAttr.enableBuffer(gl, false);
verticeAttr.enableBuffer(gl, false);
}
@Override
- public final void destroy(GL2ES2 gl, RenderState rs) {
+ protected void destroyImpl(final GL2ES2 gl, final RegionRenderer renderer) {
if(DEBUG_INSTANCE) {
System.err.println("VBORegionSPES2 Destroy: " + this);
}
- final ShaderState st = rs.getShaderState();
+ final ShaderState st = renderer.getShaderState();
if(null != verticeAttr) {
st.ownAttribute(verticeAttr, false);
verticeAttr.destroy(gl);
@@ -155,9 +131,9 @@ public class VBORegionSPES2 extends GLRegion {
texCoordAttr.destroy(gl);
texCoordAttr = null;
}
- if(null != indices) {
- indices.destroy(gl);
- indices = null;
+ if(null != indicesBuffer) {
+ indicesBuffer.destroy(gl);
+ indicesBuffer = null;
}
}
}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-1pass-weight.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-1pass_norm-weight.fp
index 7643dab7b..940e95071 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-1pass-weight.fp
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-1pass_norm-weight.fp
@@ -14,21 +14,26 @@
#include uniforms.glsl
#include varyings.glsl
+const vec3 zero3 = vec3(0);
+
void main (void)
{
+ vec3 c;
+ float alpha;
+
vec2 rtex = vec2(abs(gcv_TexCoord.x),abs(gcv_TexCoord.y));
- vec3 c = gcu_ColorStatic.rgb;
-
- float alpha = 0.0;
-
- if((gcv_TexCoord.x == 0.0) && (gcv_TexCoord.y == 0.0)) {
+
+ if( gcv_TexCoord.x == 0.0 && gcv_TexCoord.y == 0.0 ) {
+ // pass-1: Lines
+ c = gcu_ColorStatic.rgb;
alpha = gcu_Alpha;
- }
- else if ((gcv_TexCoord.x > 0.0) && (rtex.y > 0.0 || rtex.x == 1.0)) {
+ } else if ( gcv_TexCoord.x > 0.0 && ( rtex.y > 0.0 || rtex.x == 1.0 ) ) {
+ // pass-1: curves
rtex.y -= 0.1;
if(rtex.y < 0.0 && gcv_TexCoord.y < 0.0) {
// discard; // freezes NV tegra2 compiler
+ c = zero3;
alpha = 0.0;
} else {
rtex.y = max(rtex.y, 0.0);
@@ -45,10 +50,12 @@ void main (void)
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.0*rtex.x))/gd), (dty.y - (w*dty.x*(1.0 - 2.0*rtex.x))/gd));
- // FIXME: will we ever set gcu_Alpha != 1.0 ? If not, a==alpha!
- float a = clamp(0.5 - ( position/length(f) ) * sign(gcv_TexCoord.y), 0.0, 1.0);
- alpha = gcu_Alpha * a;
+ c = gcu_ColorStatic.rgb;
+ alpha = gcu_Alpha * clamp(0.5 - ( position/length(f) ) * sign(gcv_TexCoord.y), 0.0, 1.0);
}
+ } else {
+ c = zero3;
+ alpha = 0.0;
}
mgl_FragColor = vec4(c, alpha);
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-1pass.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-1pass_norm.fp
index e12eef4b1..2175c1a31 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-1pass.fp
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-1pass_norm.fp
@@ -14,21 +14,35 @@
#include uniforms.glsl
#include varyings.glsl
+const vec3 zero3 = vec3(0);
+
void main (void)
{
+ vec3 c;
+ float alpha;
+
+ /**
+ * CDTriangulator2D.extractBoundaryTriangles(..):
+ * 0 > gcv_TexCoord.y : hole or holeLike
+ * 0 < gcv_TexCoord.y : !hole (outer)
+ *
+ * 0 == gcv_TexCoord.x : vertex-0 of triangle
+ * 0.5 == gcv_TexCoord.x : vertex-1 of triangle
+ * 1 == gcv_TexCoord.x : vertex-2 of triangle
+ */
vec2 rtex = vec2(abs(gcv_TexCoord.x),abs(gcv_TexCoord.y));
- vec3 c = gcu_ColorStatic.rgb;
-
- float alpha = 0.0;
- if((gcv_TexCoord.x == 0.0) && (gcv_TexCoord.y == 0.0)) {
+ if( gcv_TexCoord.x == 0.0 && gcv_TexCoord.y == 0.0 ) {
+ // pass-1: Lines
+ c = gcu_ColorStatic.rgb;
alpha = gcu_Alpha;
- }
- else if ((gcv_TexCoord.x > 0.0) && (rtex.y > 0.0 || rtex.x == 1.0)) {
+ } else if ( gcv_TexCoord.x > 0.0 && ( rtex.y > 0.0 || rtex.x == 1.0 ) ) {
+ // pass-1: curves
rtex.y -= 0.1;
if(rtex.y < 0.0 && gcv_TexCoord.y < 0.0) {
// discard; // freezes NV tegra2 compiler
+ c = zero3;
alpha = 0.0;
} else {
rtex.y = max(rtex.y, 0.0);
@@ -39,11 +53,12 @@ void main (void)
vec2 f = vec2((dtx.y - dtx.x + 2.0*rtex.x*dtx.x), (dty.y - dty.x + 2.0*rtex.x*dty.x));
float position = rtex.y - (rtex.x * (1.0 - rtex.x));
- // FIXME: will we ever set gcu_Alpha != 1.0 ? If not, a==alpha!
- float a = clamp(0.5 - ( position/length(f) ) * sign(gcv_TexCoord.y), 0.0, 1.0);
- alpha = gcu_Alpha * a;
+ c = gcu_ColorStatic.rgb;
+ alpha = gcu_Alpha * clamp(0.5 - ( position/length(f) ) * sign(gcv_TexCoord.y), 0.0, 1.0);
}
+ } else {
+ c = zero3;
+ alpha = 0.0;
}
-
mgl_FragColor = vec4(c, alpha);
}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass-weight.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass-weight.fp
deleted file mode 100644
index fb71abd14..000000000
--- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass-weight.fp
+++ /dev/null
@@ -1,97 +0,0 @@
-//Copyright 2010 JogAmp Community. All rights reserved.
-
-//
-// 2-pass shader w/ weight
-//
-
-#if __VERSION__ >= 130
- #define varying in
- out vec4 mgl_FragColor;
- #define texture2D texture
-#else
- #define mgl_FragColor gl_FragColor
-#endif
-
-#include uniforms.glsl
-#include varyings.glsl
-
-const vec4 tex_weights = vec4(0.075, 0.06, 0.045, 0.025);
-
-void main (void)
-{
- vec2 rtex = vec2(abs(gcv_TexCoord.x),abs(gcv_TexCoord.y));
- vec3 c = gcu_ColorStatic.rgb;
-
- float alpha = 0.0;
-
- if((gcv_TexCoord.x == 0.0) && (gcv_TexCoord.y == 0.0)) {
- alpha = gcu_Alpha;
- }
- else if((gcv_TexCoord.x >= 5.0)) {
- vec2 dfx = dFdx(gcv_TexCoord);
- vec2 dfy = dFdy(gcv_TexCoord);
-
- vec2 size = 1.0/gcu_TextureSize;
-
- rtex -= 5.0;
- vec4 t = texture2D(gcu_TextureUnit, rtex)* 0.18;
-
- t += texture2D(gcu_TextureUnit, rtex + size*(vec2(1, 0)))*tex_weights.x;
- t += texture2D(gcu_TextureUnit, rtex - size*(vec2(1, 0)))*tex_weights.x;
- t += texture2D(gcu_TextureUnit, rtex + size*(vec2(0, 1)))*tex_weights.x;
- t += texture2D(gcu_TextureUnit, rtex - size*(vec2(0, 1)))*tex_weights.x;
-
- t += texture2D(gcu_TextureUnit, rtex + 2.0*size*(vec2(1, 0)))*tex_weights.y;
- t += texture2D(gcu_TextureUnit, rtex - 2.0*size*(vec2(1, 0)))*tex_weights.y;
- t += texture2D(gcu_TextureUnit, rtex + 2.0*size*(vec2(0, 1)))*tex_weights.y;
- t += texture2D(gcu_TextureUnit, rtex - 2.0*size*(vec2(0, 1)))*tex_weights.y;
-
- t += texture2D(gcu_TextureUnit, rtex + 3.0*size*(vec2(1, 0)))*tex_weights.z;
- t += texture2D(gcu_TextureUnit, rtex - 3.0*size*(vec2(1, 0)))*tex_weights.z;
- t += texture2D(gcu_TextureUnit, rtex + 3.0*size*(vec2(0, 1)))*tex_weights.z;
- t += texture2D(gcu_TextureUnit, rtex - 3.0*size*(vec2(0, 1)))*tex_weights.z;
-
- t += texture2D(gcu_TextureUnit, rtex + 4.0*size*(vec2(1, 0)))*tex_weights.w;
- t += texture2D(gcu_TextureUnit, rtex - 4.0*size*(vec2(1, 0)))*tex_weights.w;
- t += texture2D(gcu_TextureUnit, rtex + 4.0*size*(vec2(0, 1)))*tex_weights.w;
- t += texture2D(gcu_TextureUnit, rtex - 4.0*size*(vec2(0, 1)))*tex_weights.w;
-
- #if 0
- if(t.w == 0.0) {
- discard; // discard freezes NV tegra2 compiler
- }
- #endif
-
- c = t.xyz;
- alpha = gcu_Alpha * t.w;
- }
- ///////////////////////////////////////////////////////////
- else if ((gcv_TexCoord.x > 0.0) && (rtex.y > 0.0 || rtex.x == 1.0)) {
- rtex.y -= 0.1;
-
- if(rtex.y < 0.0 && gcv_TexCoord.y < 0.0) {
- // discard; // freezes NV tegra2 compiler
- alpha = 0.0;
- } else {
- rtex.y = max(rtex.y, 0.0);
-
- vec2 dtx = dFdx(rtex);
- vec2 dty = dFdy(rtex);
-
- float w = gcu_Weight;
- float pd = ((2.0 - (2.0*w))*rtex.x*rtex.x) + 2.0*(w-1.0)*rtex.x + 1.0;
- float position = rtex.y - ((w*rtex.x*(1.0 - rtex.x))/pd);
-
- 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.0*rtex.x))/gd), (dty.y - (w*dty.x*(1.0 - 2.0*rtex.x))/gd));
-
- // FIXME: will we ever set gcu_Alpha != 1.0 ? If not, a==alpha!
- float a = clamp(0.5 - ( position/length(f) ) * sign(gcv_TexCoord.y), 0.0, 1.0);
- alpha = gcu_Alpha * a;
- }
- }
-
- mgl_FragColor = vec4(c, alpha);
-}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass.fp
deleted file mode 100644
index 8e5600dd9..000000000
--- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass.fp
+++ /dev/null
@@ -1,91 +0,0 @@
-//Copyright 2010 JogAmp Community. All rights reserved.
-
-//
-// 2-pass shader w/o weight
-//
-
-#if __VERSION__ >= 130
- #define varying in
- out vec4 mgl_FragColor;
- #define texture2D texture
-#else
- #define mgl_FragColor gl_FragColor
-#endif
-
-#include uniforms.glsl
-#include varyings.glsl
-
-const vec4 tex_weights = vec4(0.075, 0.06, 0.045, 0.025);
-
-void main (void)
-{
- vec2 rtex = vec2(abs(gcv_TexCoord.x),abs(gcv_TexCoord.y));
- vec3 c = gcu_ColorStatic.rgb;
-
- float alpha = 0.0;
- float enable = 1.0;
-
- if((gcv_TexCoord.x == 0.0) && (gcv_TexCoord.y == 0.0)) {
- alpha = gcu_Alpha;
- }
- else if((gcv_TexCoord.x >= 5.0)) {
- vec2 dfx = dFdx(gcv_TexCoord);
- vec2 dfy = dFdy(gcv_TexCoord);
-
- vec2 size = 1.0/gcu_TextureSize;
-
- rtex -= 5.0;
- vec4 t = texture2D(gcu_TextureUnit, rtex)* 0.18;
-
- t += texture2D(gcu_TextureUnit, rtex + size*(vec2(1, 0)))*tex_weights.x;
- t += texture2D(gcu_TextureUnit, rtex - size*(vec2(1, 0)))*tex_weights.x;
- t += texture2D(gcu_TextureUnit, rtex + size*(vec2(0, 1)))*tex_weights.x;
- t += texture2D(gcu_TextureUnit, rtex - size*(vec2(0, 1)))*tex_weights.x;
-
- t += texture2D(gcu_TextureUnit, rtex + 2.0*size*(vec2(1, 0)))*tex_weights.y;
- t += texture2D(gcu_TextureUnit, rtex - 2.0*size*(vec2(1, 0)))*tex_weights.y;
- t += texture2D(gcu_TextureUnit, rtex + 2.0*size*(vec2(0, 1)))*tex_weights.y;
- t += texture2D(gcu_TextureUnit, rtex - 2.0*size*(vec2(0, 1)))*tex_weights.y;
-
- t += texture2D(gcu_TextureUnit, rtex + 3.0*size*(vec2(1, 0)))*tex_weights.z;
- t += texture2D(gcu_TextureUnit, rtex - 3.0*size*(vec2(1, 0)))*tex_weights.z;
- t += texture2D(gcu_TextureUnit, rtex + 3.0*size*(vec2(0, 1)))*tex_weights.z;
- t += texture2D(gcu_TextureUnit, rtex - 3.0*size*(vec2(0, 1)))*tex_weights.z;
-
- t += texture2D(gcu_TextureUnit, rtex + 4.0*size*(vec2(1, 0)))*tex_weights.w;
- t += texture2D(gcu_TextureUnit, rtex - 4.0*size*(vec2(1, 0)))*tex_weights.w;
- t += texture2D(gcu_TextureUnit, rtex + 4.0*size*(vec2(0, 1)))*tex_weights.w;
- t += texture2D(gcu_TextureUnit, rtex - 4.0*size*(vec2(0, 1)))*tex_weights.w;
-
- #if 0
- if(t.w == 0.0){
- discard; // discard freezes NV tegra2 compiler
- }
- #endif
-
- c = t.xyz;
- alpha = gcu_Alpha * t.w;
- }
- else if ((gcv_TexCoord.x > 0.0) && (rtex.y > 0.0 || rtex.x == 1.0)) {
- rtex.y -= 0.1;
-
- if(rtex.y < 0.0 && gcv_TexCoord.y < 0.0) {
- // discard; // freezes NV tegra2 compiler
- alpha = 0.0;
- } else {
- rtex.y = max(rtex.y, 0.0);
-
- vec2 dtx = dFdx(rtex);
- vec2 dty = dFdy(rtex);
-
- vec2 f = vec2((dtx.y - dtx.x + 2.0*rtex.x*dtx.x), (dty.y - dty.x + 2.0*rtex.x*dty.x));
- float position = rtex.y - (rtex.x * (1.0 - rtex.x));
-
- // FIXME: will we ever set gcu_Alpha != 1.0 ? If not, a==alpha!
- float a = clamp(0.5 - ( position/length(f) ) * sign(gcv_TexCoord.y), 0.0, 1.0);
- alpha = gcu_Alpha * a;
- }
- }
-
- mgl_FragColor = vec4(c, alpha);
-}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_msaa-weight.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_msaa-weight.fp
new file mode 100644
index 000000000..733669e64
--- /dev/null
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_msaa-weight.fp
@@ -0,0 +1,76 @@
+//Copyright 2010 JogAmp Community. All rights reserved.
+
+//
+// 2-pass shader w/ weight
+//
+
+#if __VERSION__ >= 130
+ #define varying in
+ out vec4 mgl_FragColor;
+ #define texture2D texture
+#else
+ #define mgl_FragColor gl_FragColor
+#endif
+
+#include uniforms.glsl
+#include varyings.glsl
+
+const vec3 zero3 = vec3(0);
+
+void main (void)
+{
+ vec3 c;
+ float alpha;
+
+ if( 0 < gcu_TextureSize.z ) {
+ // Pass-2: Dump Texture
+ vec4 t = texture2D(gcu_TextureUnit, gcv_TexCoord);
+ #if 0
+ if( 0.0 == t.a ) {
+ discard; // discard freezes NV tegra2 compiler
+ }
+ #endif
+
+ c = t.rgb;
+ alpha = gcu_Alpha * t.a;
+ } else {
+ // Pass-1
+ vec2 rtex = vec2(abs(gcv_TexCoord.x),abs(gcv_TexCoord.y));
+
+ if( gcv_TexCoord.x == 0.0 && gcv_TexCoord.y == 0.0 ) {
+ // pass-1: Lines
+ c = gcu_ColorStatic.rgb;
+ alpha = 1.0;
+ } else if ( gcv_TexCoord.x > 0.0 && (rtex.y > 0.0 || rtex.x == 1.0) ) {
+ // pass-1: curves
+ rtex.y -= 0.1;
+
+ if(rtex.y < 0.0 && gcv_TexCoord.y < 0.0) {
+ // discard; // freezes NV tegra2 compiler
+ c = zero3;
+ alpha = 0.0;
+ } else {
+ rtex.y = max(rtex.y, 0.0);
+
+ vec2 dtx = dFdx(rtex);
+ vec2 dty = dFdy(rtex);
+
+ float w = gcu_Weight;
+ float pd = ((2.0 - (2.0*w))*rtex.x*rtex.x) + 2.0*(w-1.0)*rtex.x + 1.0;
+ float position = rtex.y - ((w*rtex.x*(1.0 - rtex.x))/pd);
+
+ 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.0*rtex.x))/gd), (dty.y - (w*dty.x*(1.0 - 2.0*rtex.x))/gd));
+
+ c = gcu_ColorStatic.rgb;
+ alpha = clamp(0.5 - ( position/length(f) ) * sign(gcv_TexCoord.y), 0.0, 1.0);
+ }
+ } else {
+ c = zero3;
+ alpha = 0.0;
+ }
+ }
+ mgl_FragColor = vec4(c, alpha);
+}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_msaa.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_msaa.fp
new file mode 100644
index 000000000..2536e251b
--- /dev/null
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_msaa.fp
@@ -0,0 +1,88 @@
+//Copyright 2010 JogAmp Community. All rights reserved.
+
+//
+// 2-pass shader w/o weight
+//
+
+#if __VERSION__ >= 130
+ #define varying in
+ out vec4 mgl_FragColor;
+ #define texture2D texture
+#else
+ #define mgl_FragColor gl_FragColor
+#endif
+
+#include uniforms.glsl
+#include varyings.glsl
+
+// #define PREALPHA 1
+
+const vec3 zero3 = vec3(0);
+
+void main (void)
+{
+ vec3 c;
+ float alpha;
+
+ if( 0 < gcu_TextureSize.z ) {
+ // Pass-2: Dump Texture
+ vec4 t = texture2D(gcu_TextureUnit, gcv_TexCoord);
+ #if 0
+ if( 0.0 == t.a ) {
+ discard; // discard freezes NV tegra2 compiler
+ }
+ #endif
+
+ c = t.rgb;
+ #ifdef PREALPHA
+ // alpha = mix(0.0, gcu_Alpha, t.a); // t.a one of [ 0.0, 1.0 ]
+ // ^^ for = 0.0 == t.a ? 0.0 : gcu_Alpha;
+ // mix(x, y, a) := x * ( 1 - a ) + y * a
+ alpha = gcu_Alpha;
+ #else
+ alpha = gcu_Alpha * t.a;
+ #endif
+ } else {
+ // Pass-1
+ vec2 rtex = vec2(abs(gcv_TexCoord.x),abs(gcv_TexCoord.y));
+
+ if( gcv_TexCoord.x == 0.0 && gcv_TexCoord.y == 0.0 ) {
+ // pass-1: Lines
+ c = gcu_ColorStatic.rgb;
+ alpha = 1.0;
+ } else if ( gcv_TexCoord.x > 0.0 && (rtex.y > 0.0 || rtex.x == 1.0) ) {
+ // pass-1: curves
+ rtex.y -= 0.1;
+
+ if(rtex.y < 0.0 && gcv_TexCoord.y < 0.0) {
+ // discard; // freezes NV tegra2 compiler
+ c = zero3;
+ alpha = 0.0;
+ } else {
+ rtex.y = max(rtex.y, 0.0);
+
+ vec2 dtx = dFdx(rtex);
+ vec2 dty = dFdy(rtex);
+
+ vec2 f = vec2((dtx.y - dtx.x + 2.0*rtex.x*dtx.x), (dty.y - dty.x + 2.0*rtex.x*dty.x));
+ float position = rtex.y - (rtex.x * (1.0 - rtex.x));
+
+ #ifdef PREALPHA
+ float a = clamp(0.5 - ( position/length(f) ) * sign(gcv_TexCoord.y), 0.0, 1.0);
+ c = gcu_ColorStatic.rgb * a;
+ alpha = mix(1.0, 0.0, step(a, 0.0));
+ // ^^ = 0.0 < a ? 1.0 : 0.0;
+ // step(e, x) := e > x ? 0.0 : 1.0
+ // mix(x, y, a) := x * ( 1 - a ) + y * a
+ #else
+ c = gcu_ColorStatic.rgb;
+ alpha = clamp(0.5 - ( position/length(f) ) * sign(gcv_TexCoord.y), 0.0, 1.0);
+ #endif
+ }
+ } else {
+ c = zero3;
+ alpha = 0.0;
+ }
+ }
+ mgl_FragColor = vec4(c, alpha);
+}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_vbaa-weight.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_vbaa-weight.fp
new file mode 100644
index 000000000..3b1b55c87
--- /dev/null
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_vbaa-weight.fp
@@ -0,0 +1,109 @@
+//Copyright 2010 JogAmp Community. All rights reserved.
+
+//
+// 2-pass shader w/ weight
+//
+
+#if __VERSION__ >= 130
+ #define varying in
+ out vec4 mgl_FragColor;
+ #define texture2D texture
+#else
+ #define mgl_FragColor gl_FragColor
+#endif
+
+#include uniforms.glsl
+#include varyings.glsl
+
+const vec3 zero3 = vec3(0);
+
+void main (void)
+{
+ vec3 c;
+ float alpha;
+
+ if( 0 < gcu_TextureSize.z ) {
+ // Pass-2: AA on Texture
+ // Note: gcv_TexCoord is in center of sample pixels.
+
+ float sampleCount = gcu_TextureSize.z;
+ vec2 psize = 1.0 / gcu_TextureSize.xy; // pixel size
+
+ float sample_weight = 1 / ( 2 * sampleCount );
+ // float sample_weight = 1 / ( 2 * sampleCount + 1 );
+
+ vec4 t = vec4(0);
+ // vec4 t = texture2D(gcu_TextureUnit, gcv_TexCoord)* sample_weight; // center: +1
+
+ // SampleCount 2
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2(-0.5, -0.5)))*sample_weight; // NW
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2(-0.5, 0.5)))*sample_weight; // SW
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2( 0.5, 0.5)))*sample_weight; // SE
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2( 0.5, -0.5)))*sample_weight; // NE
+ if( sampleCount > 2 ) {
+ // SampleCount 4
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2(-1.5, -1.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2(-1.5, 1.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2( 1.5, 1.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2( 1.5, -1.5)))*sample_weight;
+ if( sampleCount > 4 ) {
+ // SampleCount 8
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2(-2.5, -2.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2(-2.5, 2.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2( 2.5, 2.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2( 2.5, -2.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2(-3.5, -3.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2(-3.5, 3.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2( 3.5, 3.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2( 3.5, -3.5)))*sample_weight;
+ }
+ }
+ #if 0
+ if(t.w == 0.0){
+ discard; // discard freezes NV tegra2 compiler
+ }
+ #endif
+
+ c = t.rgb;
+ alpha = gcu_Alpha * t.a;
+ } else {
+ // pass-1
+ vec2 rtex = vec2(abs(gcv_TexCoord.x),abs(gcv_TexCoord.y));
+
+ if((gcv_TexCoord.x == 0.0) && (gcv_TexCoord.y == 0.0)) {
+ // pass-1: Lines
+ c = gcu_ColorStatic.rgb;
+ alpha = 1.0;
+ } else if ( gcv_TexCoord.x > 0.0 && (rtex.y > 0.0 || rtex.x == 1.0) ) {
+ // pass-1: curves
+ rtex.y -= 0.1;
+
+ if(rtex.y < 0.0 && gcv_TexCoord.y < 0.0) {
+ // discard; // freezes NV tegra2 compiler
+ c = zero3;
+ alpha = 0.0;
+ } else {
+ rtex.y = max(rtex.y, 0.0);
+
+ vec2 dtx = dFdx(rtex);
+ vec2 dty = dFdy(rtex);
+
+ float w = gcu_Weight;
+ float pd = ((2.0 - (2.0*w))*rtex.x*rtex.x) + 2.0*(w-1.0)*rtex.x + 1.0;
+ float position = rtex.y - ((w*rtex.x*(1.0 - rtex.x))/pd);
+
+ 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.0*rtex.x))/gd), (dty.y - (w*dty.x*(1.0 - 2.0*rtex.x))/gd));
+
+ c = gcu_ColorStatic.rgb;
+ alpha = clamp(0.5 - ( position/length(f) ) * sign(gcv_TexCoord.y), 0.0, 1.0);
+ }
+ } else {
+ c = zero3;
+ alpha = 0.0;
+ }
+ }
+ mgl_FragColor = vec4(c, alpha);
+}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_vbaa.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_vbaa.fp
new file mode 100644
index 000000000..8237fa55b
--- /dev/null
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_vbaa.fp
@@ -0,0 +1,103 @@
+//Copyright 2010 JogAmp Community. All rights reserved.
+
+//
+// 2-pass shader w/o weight
+//
+
+#if __VERSION__ >= 130
+ #define varying in
+ out vec4 mgl_FragColor;
+ #define texture2D texture
+#else
+ #define mgl_FragColor gl_FragColor
+#endif
+
+#include uniforms.glsl
+#include varyings.glsl
+
+const vec3 zero3 = vec3(0);
+
+void main (void)
+{
+ vec3 c;
+ float alpha;
+
+ if( 0 < gcu_TextureSize.z ) {
+ // Pass-2: AA on Texture
+ // Note: gcv_TexCoord is in center of sample pixels.
+
+ float sampleCount = gcu_TextureSize.z;
+ vec2 psize = 1.0 / gcu_TextureSize.xy; // pixel size
+
+ float sample_weight = 1 / ( 2 * sampleCount );
+ // float sample_weight = 1 / ( 2 * sampleCount + 1 );
+
+ vec4 t = vec4(0);
+ // vec4 t = texture2D(gcu_TextureUnit, gcv_TexCoord)* sample_weight; // center: +1
+
+ // SampleCount 2
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2(-0.5, -0.5)))*sample_weight; // NW
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2(-0.5, 0.5)))*sample_weight; // SW
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2( 0.5, 0.5)))*sample_weight; // SE
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2( 0.5, -0.5)))*sample_weight; // NE
+ if( sampleCount > 2 ) {
+ // SampleCount 4
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2(-1.5, -1.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2(-1.5, 1.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2( 1.5, 1.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2( 1.5, -1.5)))*sample_weight;
+ if( sampleCount > 4 ) {
+ // SampleCount 8
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2(-2.5, -2.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2(-2.5, 2.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2( 2.5, 2.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2( 2.5, -2.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2(-3.5, -3.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2(-3.5, 3.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2( 3.5, 3.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2( 3.5, -3.5)))*sample_weight;
+ }
+ }
+ #if 0
+ if(t.w == 0.0){
+ discard; // discard freezes NV tegra2 compiler
+ }
+ #endif
+
+ c = t.rgb;
+ alpha = gcu_Alpha * t.a;
+ } else {
+ // pass-1
+ vec2 rtex = vec2(abs(gcv_TexCoord.x),abs(gcv_TexCoord.y));
+
+ if( gcv_TexCoord.x == 0.0 && gcv_TexCoord.y == 0.0 ) {
+ // pass-1: Lines
+ c = gcu_ColorStatic.rgb;
+ alpha = 1.0;
+ } else if ( gcv_TexCoord.x > 0.0 && (rtex.y > 0.0 || rtex.x == 1.0) ) {
+ // pass-1: curves
+ rtex.y -= 0.1;
+
+ if(rtex.y < 0.0 && gcv_TexCoord.y < 0.0) {
+ // discard; // freezes NV tegra2 compiler
+ c = zero3;
+ alpha = 0.0;
+ } else {
+ rtex.y = max(rtex.y, 0.0);
+
+ vec2 dtx = dFdx(rtex);
+ vec2 dty = dFdy(rtex);
+
+ vec2 f = vec2((dtx.y - dtx.x + 2.0*rtex.x*dtx.x), (dty.y - dty.x + 2.0*rtex.x*dty.x));
+ float position = rtex.y - (rtex.x * (1.0 - rtex.x));
+
+ c = gcu_ColorStatic.rgb;
+ alpha = clamp(0.5 - ( position/length(f) ) * sign(gcv_TexCoord.y), 0.0, 1.0);
+ }
+ } else {
+ c = zero3;
+ alpha = 0.0;
+ }
+ }
+ mgl_FragColor = vec4(c, alpha);
+}
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 5bbd5de14..92e78d5de 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl
@@ -6,11 +6,10 @@ uniform mat4 gcu_PMVMatrix[3]; // P, Mv, and Mvi
uniform vec3 gcu_ColorStatic;
uniform float gcu_Alpha;
uniform float gcu_Weight;
-uniform sampler2D gcu_TextureUnit;
+uniform sampler2D gcu_TextureUnit;
-// #if __VERSION__ < 130
-uniform vec2 gcu_TextureSize;
-// #endif
+/** 3rd component: 0: pass-1, >0: pass-2, sampleCount */
+uniform vec3 gcu_TextureSize;
// const int MAX_TEXTURE_UNITS = 8; // <= gl_MaxTextureImageUnits
// const int MAX_LIGHTS = 8;