summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/jogamp/graph
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-02-25 23:10:06 +0100
committerSven Gothel <[email protected]>2014-02-25 23:10:06 +0100
commitd84812b6fb398c73cb3f339ab13d74b7e6822181 (patch)
tree00a915d49855938cfb5d98701d6e63bf4c6e1977 /src/jogl/classes/jogamp/graph
parent64bdefac9191334ace292683a6a7c4274bc3f72b (diff)
Bug 802: Graph TextRenderer Performance Part-2 (fix artifacts, cleanup, incomplete)
- OutlineShape - Add DIRTY_VERTICES bit in triangulation, which in turn solves the rendering artifact issue. - transformOutlines(..) -> protected - Note: Always pick triangles first, then vertices. The former renders vertices dirty. - Region - Make triangles / vertices accessible - Add 'validateIndices()' to add indices for triangles, code moved from the GLRegion* impl. Shall be refined later! - GLRegion - Passing 'RegionRenderer' instead of RenderState .. reducing argument numbers and aligning all related 'render' methods while giving association to the RegionRenderer. - Renderer -> RegionRenderer, dropping 'intermediate' RegionRenderer - Dropping draw() in RegionRenderer, should be issued simply by GLRegion in a unique fashion. - Dropping RegionFactory Too simple code as-is, simply invoke in Region.create(..) - Overall: - Add 'final' qualifier - Remove overloaded methods where rither default args can be used or a followup method call completes the 'intention'.
Diffstat (limited to 'src/jogl/classes/jogamp/graph')
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/RegionFactory.java74
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java17
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java57
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java37
4 files changed, 36 insertions, 149 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 51198fd75..c2762591a 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);
-
}
@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, 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/VBORegion2PES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java
index 77c862ed4..22364c373 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java
@@ -41,8 +41,8 @@ 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.RegionRenderer;
import com.jogamp.graph.curve.opengl.RenderState;
import com.jogamp.opengl.FBObject;
import com.jogamp.opengl.FBObject.Attachment;
@@ -62,7 +62,7 @@ public class VBORegion2PES2 extends GLRegion {
private FBObject fbo;
private TextureAttachment texA;
- private PMVMatrix fboPMVMatrix;
+ private final PMVMatrix fboPMVMatrix;
GLUniformData mgl_fboPMVMatrix;
private int tex_width_c = 0;
@@ -70,22 +70,18 @@ public class VBORegion2PES2 extends GLRegion {
GLUniformData mgl_ActiveTexture;
GLUniformData mgl_TextureSize; // if GLSL < 1.30
- public VBORegion2PES2(int renderModes, int textureEngine) {
+ public VBORegion2PES2(final int renderModes, final int textureUnit) {
super(renderModes);
fboPMVMatrix = new PMVMatrix();
mgl_fboPMVMatrix = new GLUniformData(UniformNames.gcu_PMVMatrix, 4, 4, fboPMVMatrix.glGetPMvMatrixf());
- mgl_ActiveTexture = new GLUniformData(UniformNames.gcu_TextureUnit, textureEngine);
+ mgl_ActiveTexture = new GLUniformData(UniformNames.gcu_TextureUnit, textureUnit);
}
@Override
- public void update(GL2ES2 gl, RenderState rs) {
- if(!isDirty()) {
- return;
- }
-
+ public void update(final GL2ES2 gl, final RegionRenderer renderer) {
if(null == indicesFbo) {
final int initialElementCount = 256;
- final ShaderState st = rs.getShaderState();
+ final ShaderState st = renderer.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);
@@ -120,6 +116,7 @@ public class VBORegion2PES2 extends GLRegion {
System.err.println("VBORegion2PES2 Create: " + this);
}
}
+ validateIndices();
// process triangles
indicesTxt.seal(gl, false);
indicesTxt.rewind();
@@ -128,17 +125,7 @@ public class VBORegion2PES2 extends GLRegion {
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());
+ throw new RuntimeException("Ooops Triangle #"+i+" - has unindexed vertices");
} else {
indicesTxt.puts((short) t_vertices[0].getId());
indicesTxt.puts((short) t_vertices[1].getId());
@@ -187,22 +174,22 @@ public class VBORegion2PES2 extends GLRegion {
// 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 } ;
+ final 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){
+ protected void drawImpl(final GL2ES2 gl, final RegionRenderer renderer, final int[/*1*/] texWidth) {
+ final int width = renderer.getWidth();
+ final int height = renderer.getHeight();
+ if(width <=0 || height <= 0 || null==texWidth || texWidth[0] <= 0){
renderRegion(gl);
} else {
if(0 > maxTexSize[0]) {
gl.glGetIntegerv(GL.GL_MAX_TEXTURE_SIZE, maxTexSize, 0);
}
+ final RenderState rs = renderer.getRenderState();
if(texWidth[0] != tex_width_c) {
if(texWidth[0] > maxTexSize[0]) {
texWidth[0] = maxTexSize[0]; // clip to max - write-back user value!
@@ -210,11 +197,11 @@ public class VBORegion2PES2 extends GLRegion {
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);
+ renderFBO(gl, rs, width, height);
}
}
- private void renderFBO(GL2ES2 gl, RenderState rs, int width, int hight) {
+ private void renderFBO(final GL2ES2 gl, final RenderState rs, final int width, final int hight) {
final ShaderState st = rs.getShaderState();
gl.glViewport(0, 0, width, hight);
@@ -235,7 +222,7 @@ public class VBORegion2PES2 extends GLRegion {
// setback: gl.glActiveTexture(currentActiveTextureEngine[0]);
}
- private void renderRegion2FBO(GL2ES2 gl, RenderState rs, int[/*1*/] texWidth) {
+ private void renderRegion2FBO(final GL2ES2 gl, final RenderState rs, final int[/*1*/] texWidth) {
final ShaderState st = rs.getShaderState();
if(0>=texWidth[0]) {
@@ -280,13 +267,13 @@ public class VBORegion2PES2 extends GLRegion {
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());
+ texSize.put(0, fbo.getWidth());
+ texSize.put(1, fbo.getHeight());
st.uniform(gl, mgl_TextureSize);
//}
}
- private void renderRegion(GL2ES2 gl) {
+ private void renderRegion(final GL2ES2 gl) {
verticeTxtAttr.enableBuffer(gl, true);
texCoordTxtAttr.enableBuffer(gl, true);
indicesTxt.bindBuffer(gl, true); // keeps VBO binding
@@ -299,11 +286,11 @@ public class VBORegion2PES2 extends GLRegion {
}
@Override
- public void destroy(GL2ES2 gl, RenderState rs) {
+ public void destroy(final GL2ES2 gl, final RegionRenderer renderer) {
if(DEBUG_INSTANCE) {
System.err.println("VBORegion2PES2 Destroy: " + this);
}
- final ShaderState st = rs.getShaderState();
+ final ShaderState st = renderer.getShaderState();
if(null != fbo) {
fbo.destroy(gl);
fbo = null;
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
index 3cc6152b2..f7b9e73af 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
@@ -33,7 +33,7 @@ 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.curve.opengl.RegionRenderer;
import com.jogamp.graph.geom.Vertex;
import com.jogamp.graph.geom.Triangle;
import com.jogamp.opengl.util.GLArrayDataServer;
@@ -44,19 +44,15 @@ public class VBORegionSPES2 extends GLRegion {
private GLArrayDataServer texCoordAttr = null;
private GLArrayDataServer indicesBuffer = null;
- protected VBORegionSPES2(int renderModes) {
+ public VBORegionSPES2(final int renderModes) {
super(renderModes);
}
@Override
- protected void update(GL2ES2 gl, RenderState rs) {
- if(!isDirty()) {
- return;
- }
-
+ public void update(final GL2ES2 gl, final RegionRenderer renderer) {
if(null == indicesBuffer) {
final int initialElementCount = 256;
- final ShaderState st = rs.getShaderState();
+ final ShaderState st = renderer.getShaderState();
indicesBuffer = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialElementCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
@@ -76,6 +72,7 @@ public class VBORegionSPES2 extends GLRegion {
if(DEBUG_INSTANCE) {
System.err.println("VBORegionSPES2 Indices of "+triangles.size()+", triangles");
}
+ validateIndices();
// process triangles
indicesBuffer.seal(gl, false);
indicesBuffer.rewind();
@@ -84,21 +81,7 @@ public class VBORegionSPES2 extends GLRegion {
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]);
-
- indicesBuffer.puts((short) t_vertices[0].getId());
- indicesBuffer.puts((short) t_vertices[1].getId());
- indicesBuffer.puts((short) t_vertices[2].getId());
- if(DEBUG_INSTANCE) {
- System.err.println("VBORegionSPES2.Indices.1: "+
- t_vertices[0].getId()+", "+t_vertices[1].getId()+", "+t_vertices[2].getId());
- }
+ throw new RuntimeException("Ooops Triangle #"+i+" - has unindexed vertices");
} else {
indicesBuffer.puts((short) t_vertices[0].getId());
indicesBuffer.puts((short) t_vertices[1].getId());
@@ -133,12 +116,10 @@ public class VBORegionSPES2 extends GLRegion {
verticeAttr.enableBuffer(gl, false);
texCoordAttr.seal(gl, true);
texCoordAttr.enableBuffer(gl, false);
-
- setDirty(false);
}
@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*/] texWidth) {
verticeAttr.enableBuffer(gl, true);
texCoordAttr.enableBuffer(gl, true);
indicesBuffer.bindBuffer(gl, true); // keeps VBO binding
@@ -151,11 +132,11 @@ public class VBORegionSPES2 extends GLRegion {
}
@Override
- public final void destroy(GL2ES2 gl, RenderState rs) {
+ public void destroy(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);