diff options
Diffstat (limited to 'src/jogl/classes')
5 files changed, 186 insertions, 476 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/curve/Region.java b/src/jogl/classes/com/jogamp/graph/curve/Region.java index 0263b102f..5201d07b1 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/Region.java +++ b/src/jogl/classes/com/jogamp/graph/curve/Region.java @@ -739,6 +739,6 @@ public abstract class Region { @Override public String toString() { - return "Region["+getRenderModeString(this.renderModes)+", q "+quality+", dirty "+dirty+", vertices "+numVertices+", box "+box+"]"; + return "Region[0x"+Integer.toHexString(hashCode())+", "+getRenderModeString(this.renderModes)+", q "+quality+", dirty "+dirty+", vertices "+numVertices+", box "+box+"]"; } }
\ No newline at end of file diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java index d02ff28d0..6b8aeb04b 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java @@ -32,20 +32,26 @@ import com.jogamp.opengl.GL2ES2; import com.jogamp.opengl.GLArrayData;
import com.jogamp.opengl.util.GLArrayDataClient;
import com.jogamp.opengl.util.GLArrayDataEditable;
+import com.jogamp.opengl.util.GLArrayDataServer;
import com.jogamp.opengl.GLProfile;
+import com.jogamp.opengl.math.Vec3f;
+import com.jogamp.opengl.math.Vec4f;
import jogamp.graph.curve.opengl.VBORegion2PMSAAES2;
import jogamp.graph.curve.opengl.VBORegion2PVBAAES2;
import jogamp.graph.curve.opengl.VBORegionSPES2;
+import jogamp.graph.curve.opengl.shader.AttributeNames;
import com.jogamp.opengl.util.PMVMatrix;
import com.jogamp.opengl.util.glsl.ShaderProgram;
import com.jogamp.opengl.util.texture.TextureSequence;
import com.jogamp.graph.curve.Region;
import com.jogamp.graph.font.Font;
-import com.jogamp.graph.font.Font.Glyph;
import java.io.PrintStream;
+import java.nio.FloatBuffer;
+import java.nio.IntBuffer;
+import java.nio.ShortBuffer;
import com.jogamp.graph.curve.OutlineShape;
@@ -150,6 +156,15 @@ public abstract class GLRegion extends Region { private final int gl_idx_type;
protected final TextureSequence colorTexSeq;
+ // pass-1 common data
+ protected int curVerticesCap = 0;
+ protected int curIndicesCap = 0;
+ protected int growCount = 0;
+ protected GLArrayDataServer gca_VerticesAttr = null;
+ protected GLArrayDataServer gca_CurveParamsAttr = null;
+ protected GLArrayDataServer gca_ColorsAttr = null;
+ protected GLArrayDataServer indicesBuffer = null;
+
protected GLRegion(final GLProfile glp, final int renderModes, final TextureSequence colorTexSeq) {
super(renderModes, glp.isGL2ES3() /* use_int32_idx */);
this.gl_idx_type = usesI32Idx() ? GL.GL_UNSIGNED_INT : GL.GL_UNSIGNED_SHORT;
@@ -158,20 +173,88 @@ public abstract class GLRegion extends Region { protected final int glIdxType() { return this.gl_idx_type; }
- /**
- * Updates a graph region by updating the ogl related
- * objects for use in rendering if {@link #isShapeDirty()}.
- * <p>Allocates the ogl related data and initializes it the 1st time.<p>
- * <p>Called by {@link #draw(GL2ES2, RenderState, int, int, int)}.</p>
- * @param curRenderModes TODO
- */
- protected abstract void updateImpl(final GL2ES2 gl, int curRenderModes);
+ protected final void initBuffer(final int verticeCount, final int indexCount) {
+ indicesBuffer = GLArrayDataServer.createData(3, glIdxType(), indexCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
+ indicesBuffer.setGrowthFactor(growthFactor);
+ curIndicesCap = indicesBuffer.getElemCapacity();
- protected abstract void destroyImpl(final GL2ES2 gl);
+ gca_VerticesAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL.GL_FLOAT,
+ false, verticeCount, GL.GL_STATIC_DRAW);
+ gca_VerticesAttr.setGrowthFactor(growthFactor);
+ gca_CurveParamsAttr = GLArrayDataServer.createGLSL(AttributeNames.CURVEPARAMS_ATTR_NAME, 3, GL.GL_FLOAT,
+ false, verticeCount, GL.GL_STATIC_DRAW);
+ gca_CurveParamsAttr.setGrowthFactor(growthFactor);
+ if( hasColorChannel() ) {
+ gca_ColorsAttr = GLArrayDataServer.createGLSL(AttributeNames.COLOR_ATTR_NAME, 4, GL.GL_FLOAT,
+ false, verticeCount, GL.GL_STATIC_DRAW);
+ gca_ColorsAttr.setGrowthFactor(growthFactor);
+ }
+ curVerticesCap = gca_VerticesAttr.getElemCapacity();
+ growCount = 0;
+ }
- protected abstract void clearImpl(final GL2ES2 gl);
+ @Override
+ public final void growBuffer(final int verticesCount, final int indicesCount) {
+ boolean grown = false;
+ if( curIndicesCap < indicesBuffer.elemPosition() + indicesCount ) {
+ // System.err.printf("XXX Buffer grow - Indices: %d < ( %d = %d + %d ); Status: %s%n",
+ // curIndicesCap, indicesBuffer.elemPosition() + indicesCount, indicesBuffer.elemPosition(), indicesCount, indicesBuffer.elemStatsToString());
+ indicesBuffer.growIfNeeded(indicesCount * indicesBuffer.getCompsPerElem());
+ // System.err.println("grew.indices 0x"+Integer.toHexString(hashCode())+": "+curIndicesCap+" -> "+indicesBuffer.getElemCapacity()+", "+indicesBuffer.elemStatsToString());
+ curIndicesCap = indicesBuffer.getElemCapacity();
+ grown = true;
+ }
+ if( curVerticesCap < gca_VerticesAttr.elemPosition() + verticesCount ) {
+ // System.err.printf("XXX Buffer grow - Verices: %d < ( %d = %d + %d ); Status: %s%n",
+ // curVerticesCap, gca_VerticesAttr.elemPosition() + verticesCount, gca_VerticesAttr.elemPosition(), verticesCount, gca_VerticesAttr.elemStatsToString());
+ gca_VerticesAttr.growIfNeeded(verticesCount * gca_VerticesAttr.getCompsPerElem());
+ // System.err.println("grew.vertices 0x"+Integer.toHexString(hashCode())+": "+curVerticesCap+" -> "+gca_VerticesAttr.getElemCapacity()+", "+gca_VerticesAttr.elemStatsToString());
+ gca_CurveParamsAttr.growIfNeeded(verticesCount * gca_CurveParamsAttr.getCompsPerElem());
+ if( null != gca_ColorsAttr ) {
+ gca_ColorsAttr.growIfNeeded(verticesCount * gca_ColorsAttr.getCompsPerElem());
+ }
+ curVerticesCap = gca_VerticesAttr.getElemCapacity();
+ grown = true;
+ }
+ if( grown ) {
+ ++growCount;
+ }
+ }
+
+ @Override
+ public final void setBufferCapacity(final int verticesCount, final int indicesCount) {
+ if( curIndicesCap < indicesCount ) {
+ indicesBuffer.reserve(indicesCount);
+ curIndicesCap = indicesBuffer.getElemCapacity();
+ }
+ if( curVerticesCap < verticesCount ) {
+ gca_VerticesAttr.reserve(verticesCount);
+ gca_CurveParamsAttr.reserve(verticesCount);
+ if( null != gca_ColorsAttr ) {
+ gca_ColorsAttr.reserve(verticesCount);
+ }
+ curVerticesCap = gca_VerticesAttr.getElemCapacity();
+ }
+ }
- protected static void printAndCount(final PrintStream out, final String name, final GLArrayData data, final int[] size, final int[] capacity) {
+ @Override
+ public final void printBufferStats(final PrintStream out) {
+ final int[] size= { 0 }, capacity= { 0 };
+ out.println("GLRegion: idx32 "+usesI32Idx()+", obj 0x"+Integer.toHexString(hashCode()));
+ printAndCount(out, " indices ", indicesBuffer, size, capacity);
+ out.println();
+ printAndCount(out, " vertices ", gca_VerticesAttr, size, capacity);
+ out.println();
+ printAndCount(out, " params ", gca_CurveParamsAttr, size, capacity);
+ out.println();
+ printAndCount(out, " color ", gca_ColorsAttr, size, capacity);
+ final float filled = (float)size[0]/(float)capacity[0];
+ out.println();
+ out.printf(" total [bytes %,d / %,d], filled[%.1f%%, left %.1f%%], grow-cnt %d, obj 0x%x%n",
+ size[0], capacity[0], filled*100f, (1f-filled)*100f, growCount, hashCode());
+ }
+
+ private static void printAndCount(final PrintStream out, final String name, final GLArrayData data, final int[] size, final int[] capacity) {
out.print(name+"[");
if( null != data ) {
out.print(data.fillStatsToString());
@@ -183,6 +266,67 @@ public abstract class GLRegion extends Region { }
}
+ @Override
+ protected final void pushVertex(final Vec3f coords, final Vec3f texParams, final Vec4f rgba) {
+ // NIO array[3] is much slows than group/single
+ // gca_VerticesAttr.putf(coords, 0, 3);
+ // gca_CurveParamsAttr.putf(texParams, 0, 3);
+ // gca_VerticesAttr.put3f(coords[0], coords[1], coords[2]);
+ put3f((FloatBuffer)gca_VerticesAttr.getBuffer(), coords);
+ // gca_CurveParamsAttr.put3f(texParams[0], texParams[1], texParams[2]);
+ put3f((FloatBuffer)gca_CurveParamsAttr.getBuffer(), texParams);
+ if( null != gca_ColorsAttr ) {
+ if( null != rgba ) {
+ // gca_ColorsAttr.putf(rgba, 0, 4);
+ // gca_ColorsAttr.put4f(rgba[0], rgba[1], rgba[2], rgba[3]);
+ put4f((FloatBuffer)gca_ColorsAttr.getBuffer(), rgba);
+ } else {
+ throw new IllegalArgumentException("Null color given for COLOR_CHANNEL rendering mode");
+ }
+ }
+ }
+
+ @Override
+ protected final void pushVertices(final Vec3f coords1, final Vec3f coords2, final Vec3f coords3,
+ final Vec3f texParams1, final Vec3f texParams2, final Vec3f texParams3, final Vec4f rgba) {
+ put3f((FloatBuffer)gca_VerticesAttr.getBuffer(), coords1);
+ put3f((FloatBuffer)gca_VerticesAttr.getBuffer(), coords2);
+ put3f((FloatBuffer)gca_VerticesAttr.getBuffer(), coords3);
+ put3f((FloatBuffer)gca_CurveParamsAttr.getBuffer(), texParams1);
+ put3f((FloatBuffer)gca_CurveParamsAttr.getBuffer(), texParams2);
+ put3f((FloatBuffer)gca_CurveParamsAttr.getBuffer(), texParams3);
+ if( null != gca_ColorsAttr ) {
+ if( null != rgba ) {
+ final float r=rgba.x(), g=rgba.y(), b=rgba.z(), a=rgba.w();
+ put4f((FloatBuffer)gca_ColorsAttr.getBuffer(), r, g, b, a);
+ put4f((FloatBuffer)gca_ColorsAttr.getBuffer(), r, g, b, a);
+ put4f((FloatBuffer)gca_ColorsAttr.getBuffer(), r, g, b, a);
+ } else {
+ throw new IllegalArgumentException("Null color given for COLOR_CHANNEL rendering mode");
+ }
+ }
+ }
+
+ @Override
+ protected final void pushIndex(final int idx) {
+ if( usesI32Idx() ) {
+ indicesBuffer.puti(idx);
+ } else {
+ indicesBuffer.puts((short)idx);
+ }
+ }
+
+ @Override
+ protected final void pushIndices(final int idx1, final int idx2, final int idx3) {
+ if( usesI32Idx() ) {
+ // indicesBuffer.put3i(idx1, idx2, idx3);
+ put3i((IntBuffer)indicesBuffer.getBuffer(), idx1, idx2, idx3);
+ } else {
+ // indicesBuffer.put3s((short)idx1, (short)idx2, (short)idx3);
+ put3s((ShortBuffer)indicesBuffer.getBuffer(), (short)idx1, (short)idx2, (short)idx3);
+ }
+ }
+
/**
* Clears all buffers, i.e. triangles, vertices etc and and resets states accordingly, see {@link GLArrayDataEditable#clear(GL)}.
* <p>
@@ -193,12 +337,28 @@ public abstract class GLRegion extends Region { * @return this {@link GLRegion} for chaining.
* @see GLArrayDataEditable#clear(GL)
*/
- public GLRegion clear(final GL2ES2 gl) {
+ public final GLRegion clear(final GL2ES2 gl) {
lastRenderModes = 0;
+ if(DEBUG_INSTANCE) {
+ System.err.println("GLRegion Clear: " + this);
+ }
+ if( null != indicesBuffer ) {
+ indicesBuffer.clear(gl);
+ }
+ if( null != gca_VerticesAttr ) {
+ gca_VerticesAttr.clear(gl);
+ }
+ if( null != gca_CurveParamsAttr ) {
+ gca_CurveParamsAttr.clear(gl);
+ }
+ if( null != gca_ColorsAttr ) {
+ gca_ColorsAttr.clear(gl);
+ }
clearImpl(gl);
clearImpl();
return this;
}
+ protected abstract void clearImpl(final GL2ES2 gl);
/**
* Delete and clear the associated OGL objects.
@@ -211,6 +371,7 @@ public abstract class GLRegion extends Region { clear(gl);
destroyImpl(gl);
}
+ protected abstract void destroyImpl(final GL2ES2 gl);
/**
* Renders the associated OGL objects specifying
@@ -267,5 +428,14 @@ public abstract class GLRegion extends Region { }
private int lastRenderModes = 0;
+ /**
+ * Updates a graph region by updating the ogl related
+ * objects for use in rendering if {@link #isShapeDirty()}.
+ * <p>Allocates the ogl related data and initializes it the 1st time.<p>
+ * <p>Called by {@link #draw(GL2ES2, RenderState, int, int, int)}.</p>
+ * @param curRenderModes TODO
+ */
+ protected abstract void updateImpl(final GL2ES2 gl, int curRenderModes);
+
protected abstract void drawImpl(final GL2ES2 gl, final RegionRenderer renderer, int curRenderModes, final int[/*1*/] sampleCount);
}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java index c6c7f567c..a6401fbd7 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java @@ -27,10 +27,7 @@ */ package jogamp.graph.curve.opengl; -import java.io.PrintStream; import java.nio.FloatBuffer; -import java.nio.IntBuffer; -import java.nio.ShortBuffer; import com.jogamp.opengl.GL2ES2; import com.jogamp.opengl.GLProfile; @@ -48,8 +45,6 @@ import com.jogamp.opengl.FBObject; import com.jogamp.opengl.FBObject.Attachment; import com.jogamp.opengl.math.Matrix4f; import com.jogamp.opengl.math.Recti; -import com.jogamp.opengl.math.Vec3f; -import com.jogamp.opengl.math.Vec4f; import com.jogamp.opengl.math.geom.AABBox; import com.jogamp.opengl.util.GLArrayDataServer; import com.jogamp.opengl.util.SyncMatrices4f16; @@ -65,12 +60,6 @@ public final class VBORegion2PMSAAES2 extends GLRegion { private final RenderState.ProgramLocal rsLocal; // Pass-1: - private int curVerticesCap = 0; - private int curIndicesCap = 0; - private GLArrayDataServer gca_VerticesAttr; - private GLArrayDataServer gca_CurveParamsAttr; - private GLArrayDataServer gca_ColorsAttr; - private GLArrayDataServer indicesBuffer; private final GLUniformData gcu_ColorTexUnit; private final float[] colorTexBBox; // x0, y0, x1, y1 private final GLUniformData gcu_ColorTexBBox; @@ -137,144 +126,12 @@ public final class VBORegion2PMSAAES2 extends GLRegion { false, 4, GL.GL_STATIC_DRAW); } - private void initBuffer(final int verticeCount, final int indexCount) { - indicesBuffer = GLArrayDataServer.createData(3, glIdxType(), indexCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER); - indicesBuffer.setGrowthFactor(growthFactor); - curIndicesCap = indicesBuffer.getElemCapacity(); - - gca_VerticesAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL.GL_FLOAT, - false, verticeCount, GL.GL_STATIC_DRAW); - gca_VerticesAttr.setGrowthFactor(growthFactor); - gca_CurveParamsAttr = GLArrayDataServer.createGLSL(AttributeNames.CURVEPARAMS_ATTR_NAME, 3, GL.GL_FLOAT, - false, verticeCount, GL.GL_STATIC_DRAW); - gca_CurveParamsAttr.setGrowthFactor(growthFactor); - if( hasColorChannel() ) { - gca_ColorsAttr = GLArrayDataServer.createGLSL(AttributeNames.COLOR_ATTR_NAME, 4, GL.GL_FLOAT, - false, verticeCount, GL.GL_STATIC_DRAW); - gca_ColorsAttr.setGrowthFactor(growthFactor); - } - curVerticesCap = gca_VerticesAttr.getElemCapacity(); - } - - @Override - public void growBuffer(final int verticesCount, final int indicesCount) { - if( curIndicesCap < indicesBuffer.elemPosition() + indicesCount ) { - indicesBuffer.growIfNeeded(indicesCount * indicesBuffer.getCompsPerElem()); - curIndicesCap = indicesBuffer.getElemCapacity(); - } - if( curVerticesCap < gca_VerticesAttr.elemPosition() + verticesCount ) { - gca_VerticesAttr.growIfNeeded(verticesCount * gca_VerticesAttr.getCompsPerElem()); - gca_CurveParamsAttr.growIfNeeded(verticesCount * gca_CurveParamsAttr.getCompsPerElem()); - if( null != gca_ColorsAttr ) { - gca_ColorsAttr.growIfNeeded(verticesCount * gca_ColorsAttr.getCompsPerElem()); - } - curVerticesCap = gca_VerticesAttr.getElemCapacity(); - } - } - - @Override - public void setBufferCapacity(final int verticesCount, final int indicesCount) { - if( curIndicesCap < indicesCount ) { - indicesBuffer.reserve(indicesCount); - curIndicesCap = indicesBuffer.getElemCapacity(); - } - if( curVerticesCap < verticesCount ) { - gca_VerticesAttr.reserve(verticesCount); - gca_CurveParamsAttr.reserve(verticesCount); - if( null != gca_ColorsAttr ) { - gca_ColorsAttr.reserve(verticesCount); - } - curVerticesCap = gca_VerticesAttr.getElemCapacity(); - } - } - @Override protected final void clearImpl(final GL2ES2 gl) { - if( null != indicesBuffer ) { - indicesBuffer.clear(gl); - } - if( null != gca_VerticesAttr ) { - gca_VerticesAttr.clear(gl); - } - if( null != gca_CurveParamsAttr ) { - gca_CurveParamsAttr.clear(gl); - } - if( null != gca_ColorsAttr ) { - gca_ColorsAttr.clear(gl); - } fboDirty = true; } @Override - public void printBufferStats(final PrintStream out) { - final int[] size= { 0 }, capacity= { 0 }; - out.println("VBORegion2PMSAAES2: idx32 "+usesI32Idx()); - printAndCount(out, " indices ", indicesBuffer, size, capacity); - out.println(); - printAndCount(out, " vertices ", gca_VerticesAttr, size, capacity); - out.println(); - printAndCount(out, " params ", gca_CurveParamsAttr, size, capacity); - out.println(); - printAndCount(out, " color ", gca_ColorsAttr, size, capacity); - final float filled = (float)size[0]/(float)capacity[0]; - out.println(); - out.printf(" total [bytes %,d / %,d], filled %.1f%%, left %.1f%%]%n", - size[0], capacity[0], filled*100f, (1f-filled)*100f); - } - - @Override - protected final void pushVertex(final Vec3f coords, final Vec3f texParams, final Vec4f rgba) { - put3f((FloatBuffer)gca_VerticesAttr.getBuffer(), coords); - put3f((FloatBuffer)gca_CurveParamsAttr.getBuffer(), texParams); - if( null != gca_ColorsAttr ) { - if( null != rgba ) { - put4f((FloatBuffer)gca_ColorsAttr.getBuffer(), rgba); - } else { - throw new IllegalArgumentException("Null color given for COLOR_CHANNEL rendering mode"); - } - } - } - - @Override - protected final void pushVertices(final Vec3f coords1, final Vec3f coords2, final Vec3f coords3, - final Vec3f texParams1, final Vec3f texParams2, final Vec3f texParams3, final Vec4f rgba) { - put3f((FloatBuffer)gca_VerticesAttr.getBuffer(), coords1); - put3f((FloatBuffer)gca_VerticesAttr.getBuffer(), coords2); - put3f((FloatBuffer)gca_VerticesAttr.getBuffer(), coords3); - put3f((FloatBuffer)gca_CurveParamsAttr.getBuffer(), texParams1); - put3f((FloatBuffer)gca_CurveParamsAttr.getBuffer(), texParams2); - put3f((FloatBuffer)gca_CurveParamsAttr.getBuffer(), texParams3); - if( null != gca_ColorsAttr ) { - if( null != rgba ) { - final float r=rgba.x(), g=rgba.y(), b=rgba.z(), a=rgba.w(); - put4f((FloatBuffer)gca_ColorsAttr.getBuffer(), r, g, b, a); - put4f((FloatBuffer)gca_ColorsAttr.getBuffer(), r, g, b, a); - put4f((FloatBuffer)gca_ColorsAttr.getBuffer(), r, g, b, a); - } else { - throw new IllegalArgumentException("Null color given for COLOR_CHANNEL rendering mode"); - } - } - } - - @Override - protected final void pushIndex(final int idx) { - if( usesI32Idx() ) { - indicesBuffer.puti(idx); - } else { - indicesBuffer.puts((short)idx); - } - } - - @Override - protected final void pushIndices(final int idx1, final int idx2, final int idx3) { - if( usesI32Idx() ) { - put3i((IntBuffer)indicesBuffer.getBuffer(), idx1, idx2, idx3); - } else { - put3s((ShortBuffer)indicesBuffer.getBuffer(), (short)idx1, (short)idx2, (short)idx3); - } - } - - @Override protected void updateImpl(final GL2ES2 gl, final int curRenderModes) { final boolean hasColorChannel = Region.hasColorChannel( curRenderModes ); final boolean hasColorTexture = Region.hasColorTexture( curRenderModes ); diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java index 1b580437f..49c91ce4b 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java @@ -27,10 +27,7 @@ */ package jogamp.graph.curve.opengl; -import java.io.PrintStream; import java.nio.FloatBuffer; -import java.nio.IntBuffer; -import java.nio.ShortBuffer; import com.jogamp.opengl.GL2ES2; import com.jogamp.opengl.GLProfile; @@ -51,8 +48,6 @@ import com.jogamp.opengl.FBObject.Attachment; import com.jogamp.opengl.FBObject.TextureAttachment; import com.jogamp.opengl.math.Matrix4f; import com.jogamp.opengl.math.Recti; -import com.jogamp.opengl.math.Vec3f; -import com.jogamp.opengl.math.Vec4f; import com.jogamp.opengl.math.geom.AABBox; import com.jogamp.opengl.util.GLArrayDataServer; import com.jogamp.opengl.util.SyncMatrices4f16; @@ -98,12 +93,6 @@ public final class VBORegion2PVBAAES2 extends GLRegion { private final RenderState.ProgramLocal rsLocal; // Pass-1: - private int curVerticesCap = 0; - private int curIndicesCap = 0; - private GLArrayDataServer gca_VerticesAttr; - private GLArrayDataServer gca_CurveParamsAttr; - private GLArrayDataServer gca_ColorsAttr; - private GLArrayDataServer indicesBuffer; private final GLUniformData gcu_ColorTexUnit; private final float[] colorTexBBox; // x0, y0, x1, y1 private final GLUniformData gcu_ColorTexBBox; @@ -230,170 +219,12 @@ public final class VBORegion2PVBAAES2 extends GLRegion { false, 4, GL.GL_STATIC_DRAW); } - private void initBuffer(final int verticeCount, final int indexCount) { - indicesBuffer = GLArrayDataServer.createData(3, glIdxType(), indexCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER); - indicesBuffer.setGrowthFactor(growthFactor); - curIndicesCap = indicesBuffer.getElemCapacity(); - - gca_VerticesAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL.GL_FLOAT, - false, verticeCount, GL.GL_STATIC_DRAW); - gca_VerticesAttr.setGrowthFactor(growthFactor); - gca_CurveParamsAttr = GLArrayDataServer.createGLSL(AttributeNames.CURVEPARAMS_ATTR_NAME, 3, GL.GL_FLOAT, - false, verticeCount, GL.GL_STATIC_DRAW); - gca_CurveParamsAttr.setGrowthFactor(growthFactor); - if( hasColorChannel() ) { - gca_ColorsAttr = GLArrayDataServer.createGLSL(AttributeNames.COLOR_ATTR_NAME, 4, GL.GL_FLOAT, - false, verticeCount, GL.GL_STATIC_DRAW); - gca_ColorsAttr.setGrowthFactor(growthFactor); - } - curVerticesCap = gca_VerticesAttr.getElemCapacity(); - } - - @Override - public void growBuffer(final int verticesCount, final int indicesCount) { - if( curIndicesCap < indicesBuffer.elemPosition() + indicesCount ) { - // System.err.printf("XXX Buffer grow - Indices: %d < ( %d = %d + %d ); Status: %s%n", - // curIndicesCap, indicesBuffer.elemPosition() + indicesCount, indicesBuffer.elemPosition(), indicesCount, indicesBuffer.elemStatsToString()); - indicesBuffer.growIfNeeded(indicesCount * indicesBuffer.getCompsPerElem()); - curIndicesCap = indicesBuffer.getElemCapacity(); - } - if( curVerticesCap < gca_VerticesAttr.elemPosition() + verticesCount ) { - // System.err.printf("XXX Buffer grow - Verices: %d < ( %d = %d + %d ); Status: %s%n", - // curVerticesCap, gca_VerticesAttr.elemPosition() + verticesCount, gca_VerticesAttr.elemPosition(), verticesCount, gca_VerticesAttr.elemStatsToString()); - gca_VerticesAttr.growIfNeeded(verticesCount * gca_VerticesAttr.getCompsPerElem()); - gca_CurveParamsAttr.growIfNeeded(verticesCount * gca_CurveParamsAttr.getCompsPerElem()); - if( null != gca_ColorsAttr ) { - gca_ColorsAttr.growIfNeeded(verticesCount * gca_ColorsAttr.getCompsPerElem()); - } - curVerticesCap = gca_VerticesAttr.getElemCapacity(); - } - } - - @Override - public void setBufferCapacity(final int verticesCount, final int indicesCount) { - if( curIndicesCap < indicesCount ) { - indicesBuffer.reserve(indicesCount); - curIndicesCap = indicesBuffer.getElemCapacity(); - } - if( curVerticesCap < verticesCount ) { - gca_VerticesAttr.reserve(verticesCount); - gca_CurveParamsAttr.reserve(verticesCount); - if( null != gca_ColorsAttr ) { - gca_ColorsAttr.reserve(verticesCount); - } - curVerticesCap = gca_VerticesAttr.getElemCapacity(); - } - } - @Override protected final void clearImpl(final GL2ES2 gl) { - if(DEBUG_INSTANCE) { - System.err.println("VBORegion2PES2 Clear: " + this); - // Thread.dumpStack(); - } - if( null != indicesBuffer ) { - indicesBuffer.clear(gl); - } - if( null != gca_VerticesAttr ) { - gca_VerticesAttr.clear(gl); - } - if( null != gca_CurveParamsAttr ) { - gca_CurveParamsAttr.clear(gl); - } - if( null != gca_ColorsAttr ) { - gca_ColorsAttr.clear(gl);; - } fboDirty = true; } @Override - public void printBufferStats(final PrintStream out) { - final int[] size= { 0 }, capacity= { 0 }; - out.println("VBORegion2PVBAAES2: idx32 "+usesI32Idx()); - printAndCount(out, " indices ", indicesBuffer, size, capacity); - out.println(); - printAndCount(out, " vertices ", gca_VerticesAttr, size, capacity); - out.println(); - printAndCount(out, " params ", gca_CurveParamsAttr, size, capacity); - out.println(); - printAndCount(out, " color ", gca_ColorsAttr, size, capacity); - final float filled = (float)size[0]/(float)capacity[0]; - out.println(); - out.printf(" total [bytes %,d / %,d], filled %.1f%%, left %.1f%%]%n", - size[0], capacity[0], filled*100f, (1f-filled)*100f); - } - - @Override - protected final void pushVertex(final Vec3f coords, final Vec3f texParams, final Vec4f rgba) { - // NIO array[3] is much slows than group/single - // gca_VerticesAttr.putf(coords, 0, 3); - // gca_CurveParamsAttr.putf(texParams, 0, 3); - // gca_VerticesAttr.put3f(coords[0], coords[1], coords[2]); - put3f((FloatBuffer)gca_VerticesAttr.getBuffer(), coords); - // gca_CurveParamsAttr.put3f(texParams[0], texParams[1], texParams[2]); - put3f((FloatBuffer)gca_CurveParamsAttr.getBuffer(), texParams); - if( null != gca_ColorsAttr ) { - if( null != rgba ) { - // gca_ColorsAttr.putf(rgba, 0, 4); - // gca_ColorsAttr.put4f(rgba[0], rgba[1], rgba[2], rgba[3]); - put4f((FloatBuffer)gca_ColorsAttr.getBuffer(), rgba); - } else { - throw new IllegalArgumentException("Null color given for COLOR_CHANNEL rendering mode"); - } - } - } - - @Override - protected final void pushVertices(final Vec3f coords1, final Vec3f coords2, final Vec3f coords3, - final Vec3f texParams1, final Vec3f texParams2, final Vec3f texParams3, final Vec4f rgba) { - // gca_VerticesAttr.put3f(coords1[0], coords1[1], coords1[2]); - // gca_VerticesAttr.put3f(coords2[0], coords2[1], coords2[2]); - // gca_VerticesAttr.put3f(coords3[0], coords3[1], coords3[2]); - put3f((FloatBuffer)gca_VerticesAttr.getBuffer(), coords1); - put3f((FloatBuffer)gca_VerticesAttr.getBuffer(), coords2); - put3f((FloatBuffer)gca_VerticesAttr.getBuffer(), coords3); - // gca_CurveParamsAttr.put3f(texParams1[0], texParams1[1], texParams1[2]); - // gca_CurveParamsAttr.put3f(texParams2[0], texParams2[1], texParams2[2]); - // gca_CurveParamsAttr.put3f(texParams3[0], texParams3[1], texParams3[2]); - put3f((FloatBuffer)gca_CurveParamsAttr.getBuffer(), texParams1); - put3f((FloatBuffer)gca_CurveParamsAttr.getBuffer(), texParams2); - put3f((FloatBuffer)gca_CurveParamsAttr.getBuffer(), texParams3); - if( null != gca_ColorsAttr ) { - if( null != rgba ) { - final float r=rgba.x(), g=rgba.y(), b=rgba.z(), a=rgba.w(); - // gca_ColorsAttr.put4f(r, g, b, a); - // gca_ColorsAttr.put4f(r, g, b, a); - // gca_ColorsAttr.put4f(r, g, b, a); - put4f((FloatBuffer)gca_ColorsAttr.getBuffer(), r, g, b, a); - put4f((FloatBuffer)gca_ColorsAttr.getBuffer(), r, g, b, a); - put4f((FloatBuffer)gca_ColorsAttr.getBuffer(), r, g, b, a); - } else { - throw new IllegalArgumentException("Null color given for COLOR_CHANNEL rendering mode"); - } - } - } - - @Override - protected final void pushIndex(final int idx) { - if( usesI32Idx() ) { - indicesBuffer.puti(idx); - } else { - indicesBuffer.puts((short)idx); - } - } - - @Override - protected final void pushIndices(final int idx1, final int idx2, final int idx3) { - if( usesI32Idx() ) { - // indicesBuffer.put3i(idx1, idx2, idx3); - put3i((IntBuffer)indicesBuffer.getBuffer(), idx1, idx2, idx3); - } else { - // indicesBuffer.put3s((short)idx1, (short)idx2, (short)idx3); - put3s((ShortBuffer)indicesBuffer.getBuffer(), (short)idx1, (short)idx2, (short)idx3); - } - } - - @Override protected void updateImpl(final GL2ES2 gl, final int curRenderModes) { final boolean hasColorChannel = Region.hasColorChannel( curRenderModes ); final boolean hasColorTexture = Region.hasColorTexture( curRenderModes ); diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java index e149203f9..97948c204 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java @@ -27,26 +27,19 @@ */ package jogamp.graph.curve.opengl; -import java.io.PrintStream; import java.nio.FloatBuffer; -import java.nio.IntBuffer; -import java.nio.ShortBuffer; import com.jogamp.opengl.GL; import com.jogamp.opengl.GL2ES2; import com.jogamp.opengl.GLProfile; import com.jogamp.opengl.GLUniformData; -import com.jogamp.opengl.math.Vec3f; -import com.jogamp.opengl.math.Vec4f; -import jogamp.graph.curve.opengl.shader.AttributeNames; import jogamp.graph.curve.opengl.shader.UniformNames; import com.jogamp.graph.curve.Region; import com.jogamp.graph.curve.opengl.GLRegion; import com.jogamp.graph.curve.opengl.RegionRenderer; import com.jogamp.graph.curve.opengl.RenderState; -import com.jogamp.opengl.util.GLArrayDataServer; import com.jogamp.opengl.util.glsl.ShaderProgram; import com.jogamp.opengl.util.texture.Texture; import com.jogamp.opengl.util.texture.TextureCoords; @@ -55,12 +48,7 @@ import com.jogamp.opengl.util.texture.TextureSequence; public final class VBORegionSPES2 extends GLRegion { private final RenderState.ProgramLocal rsLocal; - private int curVerticesCap = 0; - private int curIndicesCap = 0; - private GLArrayDataServer gca_VerticesAttr = null; - private GLArrayDataServer gca_CurveParamsAttr = null; - private GLArrayDataServer gca_ColorsAttr; - private GLArrayDataServer indicesBuffer = null; + // Pass-1: private final GLUniformData gcu_ColorTexUnit; private final float[] colorTexBBox; // x0, y0, x1, y1 private final GLUniformData gcu_ColorTexBBox; @@ -86,144 +74,8 @@ public final class VBORegionSPES2 extends GLRegion { } } - private void initBuffer(final int verticeCount, final int indexCount) { - indicesBuffer = GLArrayDataServer.createData(3, glIdxType(), indexCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER); - indicesBuffer.setGrowthFactor(growthFactor); - curIndicesCap = indicesBuffer.getElemCapacity(); - - gca_VerticesAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL.GL_FLOAT, - false, verticeCount, GL.GL_STATIC_DRAW); - gca_VerticesAttr.setGrowthFactor(growthFactor); - gca_CurveParamsAttr = GLArrayDataServer.createGLSL(AttributeNames.CURVEPARAMS_ATTR_NAME, 3, GL.GL_FLOAT, - false, verticeCount, GL.GL_STATIC_DRAW); - gca_CurveParamsAttr.setGrowthFactor(growthFactor); - if( hasColorChannel() ) { - gca_ColorsAttr = GLArrayDataServer.createGLSL(AttributeNames.COLOR_ATTR_NAME, 4, GL.GL_FLOAT, - false, verticeCount, GL.GL_STATIC_DRAW); - gca_ColorsAttr.setGrowthFactor(growthFactor); - } - curVerticesCap = gca_VerticesAttr.getElemCapacity(); - } - - @Override - public void growBuffer(final int verticesCount, final int indicesCount) { - if( curIndicesCap < indicesBuffer.elemPosition() + indicesCount ) { - indicesBuffer.growIfNeeded(indicesCount * indicesBuffer.getCompsPerElem()); - curIndicesCap = indicesBuffer.getElemCapacity(); - } - if( curVerticesCap < gca_VerticesAttr.elemPosition() + verticesCount ) { - gca_VerticesAttr.growIfNeeded(verticesCount * gca_VerticesAttr.getCompsPerElem()); - gca_CurveParamsAttr.growIfNeeded(verticesCount * gca_CurveParamsAttr.getCompsPerElem()); - if( null != gca_ColorsAttr ) { - gca_ColorsAttr.growIfNeeded(verticesCount * gca_ColorsAttr.getCompsPerElem()); - } - curVerticesCap = gca_VerticesAttr.getElemCapacity(); - } - } - - @Override - public void setBufferCapacity(final int verticesCount, final int indicesCount) { - if( curIndicesCap < indicesCount ) { - indicesBuffer.reserve(indicesCount); - curIndicesCap = indicesBuffer.getElemCapacity(); - } - if( curVerticesCap < verticesCount ) { - gca_VerticesAttr.reserve(verticesCount); - gca_CurveParamsAttr.reserve(verticesCount); - if( null != gca_ColorsAttr ) { - gca_ColorsAttr.reserve(verticesCount); - } - curVerticesCap = gca_VerticesAttr.getElemCapacity(); - } - } - - @Override - protected final void clearImpl(final GL2ES2 gl) { - if(DEBUG_INSTANCE) { - System.err.println("VBORegionSPES2 Clear: " + this); - } - if( null != indicesBuffer ) { - indicesBuffer.clear(gl); - } - if( null != gca_VerticesAttr ) { - gca_VerticesAttr.clear(gl); - } - if( null != gca_CurveParamsAttr ) { - gca_CurveParamsAttr.clear(gl); - } - if( null != gca_ColorsAttr ) { - gca_ColorsAttr.clear(gl); - } - } - - @Override - public void printBufferStats(final PrintStream out) { - final int[] size= { 0 }, capacity= { 0 }; - out.println("VBORegionSPES2: idx32 "+usesI32Idx()); - printAndCount(out, " indices ", indicesBuffer, size, capacity); - out.println(); - printAndCount(out, " vertices ", gca_VerticesAttr, size, capacity); - out.println(); - printAndCount(out, " params ", gca_CurveParamsAttr, size, capacity); - out.println(); - printAndCount(out, " color ", gca_ColorsAttr, size, capacity); - final float filled = (float)size[0]/(float)capacity[0]; - out.println(); - out.printf(" total [bytes %,d / %,d], filled %.1f%%, left %.1f%%]%n", - size[0], capacity[0], filled*100f, (1f-filled)*100f); - } - - @Override - protected final void pushVertex(final Vec3f coords, final Vec3f texParams, final Vec4f rgba) { - put3f((FloatBuffer)gca_VerticesAttr.getBuffer(), coords); - put3f((FloatBuffer)gca_CurveParamsAttr.getBuffer(), texParams); - if( null != gca_ColorsAttr ) { - if( null != rgba ) { - put4f((FloatBuffer)gca_ColorsAttr.getBuffer(), rgba); - } else { - throw new IllegalArgumentException("Null color given for COLOR_CHANNEL rendering mode"); - } - } - } - - @Override - protected final void pushVertices(final Vec3f coords1, final Vec3f coords2, final Vec3f coords3, - final Vec3f texParams1, final Vec3f texParams2, final Vec3f texParams3, final Vec4f rgba) { - put3f((FloatBuffer)gca_VerticesAttr.getBuffer(), coords1); - put3f((FloatBuffer)gca_VerticesAttr.getBuffer(), coords2); - put3f((FloatBuffer)gca_VerticesAttr.getBuffer(), coords3); - put3f((FloatBuffer)gca_CurveParamsAttr.getBuffer(), texParams1); - put3f((FloatBuffer)gca_CurveParamsAttr.getBuffer(), texParams2); - put3f((FloatBuffer)gca_CurveParamsAttr.getBuffer(), texParams3); - if( null != gca_ColorsAttr ) { - if( null != rgba ) { - final float r=rgba.x(), g=rgba.y(), b=rgba.z(), a=rgba.w(); - put4f((FloatBuffer)gca_ColorsAttr.getBuffer(), r, g, b, a); - put4f((FloatBuffer)gca_ColorsAttr.getBuffer(), r, g, b, a); - put4f((FloatBuffer)gca_ColorsAttr.getBuffer(), r, g, b, a); - } else { - throw new IllegalArgumentException("Null color given for COLOR_CHANNEL rendering mode"); - } - } - } - - @Override - protected final void pushIndex(final int idx) { - if( usesI32Idx() ) { - indicesBuffer.puti(idx); - } else { - indicesBuffer.puts((short)idx); - } - } - @Override - protected final void pushIndices(final int idx1, final int idx2, final int idx3) { - if( usesI32Idx() ) { - put3i((IntBuffer)indicesBuffer.getBuffer(), idx1, idx2, idx3); - } else { - put3s((ShortBuffer)indicesBuffer.getBuffer(), (short)idx1, (short)idx2, (short)idx3); - } - } + protected final void clearImpl(final GL2ES2 gl) { } @Override protected void updateImpl(final GL2ES2 gl, final int curRenderModes) { |