From 624a52690b429c486bb8946d58f77936ead41785 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 8 May 2011 05:34:16 +0200 Subject: Graph VBORegion*: Lazy GL alloc of resources at update(GL, ..) not constructor --- .../jogamp/graph/curve/opengl/VBORegion2PES2.java | 221 +++++++++------------ .../jogamp/graph/curve/opengl/VBORegionSPES2.java | 153 +++++--------- 2 files changed, 141 insertions(+), 233 deletions(-) (limited to 'src/jogl/classes/jogamp/graph/curve/opengl') diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java index 90b3d47cd..5645393bb 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java @@ -27,7 +27,7 @@ */ package jogamp.graph.curve.opengl; -import java.util.ArrayList; +import java.nio.FloatBuffer; import javax.media.opengl.GL2ES2; // FIXME: Subsume GL2GL3.GL_DRAW_FRAMEBUFFER -> GL2ES2.GL_DRAW_FRAMEBUFFER ! @@ -38,22 +38,18 @@ import javax.media.opengl.fixedfunc.GLMatrixFunc; import jogamp.graph.curve.opengl.shader.AttributeNames; import jogamp.graph.curve.opengl.shader.UniformNames; -import com.jogamp.graph.geom.AABBox; +import com.jogamp.common.nio.Buffers; import com.jogamp.graph.geom.Triangle; import com.jogamp.graph.geom.Vertex; -import com.jogamp.graph.curve.Region; +import com.jogamp.graph.curve.opengl.GLRegion; import com.jogamp.graph.curve.opengl.RenderState; import com.jogamp.opengl.util.FBObject; import com.jogamp.opengl.util.GLArrayDataServer; import com.jogamp.opengl.util.PMVMatrix; import com.jogamp.opengl.util.glsl.ShaderState; -public class VBORegion2PES2 implements Region { - private int numVertices = 0; - - private ArrayList triangles = new ArrayList(); - private ArrayList vertices = new ArrayList(); +public class VBORegion2PES2 extends GLRegion { private GLArrayDataServer verticeTxtAttr; private GLArrayDataServer texCoordTxtAttr; private GLArrayDataServer indicesTxt; @@ -61,97 +57,90 @@ public class VBORegion2PES2 implements Region { private GLArrayDataServer texCoordFboAttr; private GLArrayDataServer indicesFbo; - private boolean flipped = false; - - private boolean dirty = true; - private AABBox box; private FBObject fbo; - private PMVMatrix fboPMVMatrix; GLUniformData mgl_fboPMVMatrix; private int tex_width_c = 0; private int tex_height_c = 0; GLUniformData mgl_ActiveTexture; - int activeTexture; // texture engine 0 == GL.GL_TEXTURE0 + GLUniformData mgl_TextureSize; // if GLSL < 1.30 + final int activeTexture; // texture engine 0 == GL.GL_TEXTURE0 - public VBORegion2PES2(RenderState rs, int textureEngine) { - fboPMVMatrix = new PMVMatrix(); - mgl_fboPMVMatrix = new GLUniformData(UniformNames.gcu_PMVMatrix, 4, 4, fboPMVMatrix.glGetPMvMatrixf()); - + public VBORegion2PES2(int renderModes, int textureEngine) { + super(renderModes); activeTexture = GL.GL_TEXTURE0 + textureEngine; - mgl_ActiveTexture = new GLUniformData(UniformNames.gcu_TextureUnit, textureEngine); - - final int initialSize = 256; - final ShaderState st = rs.getShaderState(); - - indicesFbo = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialSize, 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(st, AttributeNames.TEXCOORD_ATTR_NAME, 2, - GL2ES2.GL_FLOAT, false, initialSize, 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(st, AttributeNames.VERTEX_ATTR_NAME, 3, - GL2ES2.GL_FLOAT, false, initialSize, GL.GL_STATIC_DRAW); - st.ownAttribute(verticeFboAttr, true); - - - box = new AABBox(); - - indicesTxt = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialSize, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER); - - verticeTxtAttr = GLArrayDataServer.createGLSL(st, AttributeNames.VERTEX_ATTR_NAME, 3, - GL2ES2.GL_FLOAT, false, initialSize, GL.GL_STATIC_DRAW); - st.ownAttribute(verticeTxtAttr, true); - - texCoordTxtAttr = GLArrayDataServer.createGLSL(st, AttributeNames.TEXCOORD_ATTR_NAME, 2, - GL2ES2.GL_FLOAT, false, initialSize, GL.GL_STATIC_DRAW); - st.ownAttribute(texCoordTxtAttr, true); - - if(DEBUG_INSTANCE) { - System.err.println("VBORegion2PES2 Create: " + this); - } + fboPMVMatrix = new PMVMatrix(); + mgl_fboPMVMatrix = new GLUniformData(UniformNames.gcu_PMVMatrix, 4, 4, fboPMVMatrix.glGetPMvMatrixf()); + mgl_ActiveTexture = new GLUniformData(UniformNames.gcu_TextureUnit, textureEngine); } - public void update(GL2ES2 gl){ - if(!dirty) { + public void update(GL2ES2 gl, RenderState rs) { + if(!isDirty()) { return; } - + + if(null == indicesFbo) { + final int initialSize = 256; + final ShaderState st = rs.getShaderState(); + + indicesFbo = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialSize, 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(st, AttributeNames.TEXCOORD_ATTR_NAME, 2, + GL2ES2.GL_FLOAT, false, initialSize, 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(st, AttributeNames.VERTEX_ATTR_NAME, 3, + GL2ES2.GL_FLOAT, false, initialSize, GL.GL_STATIC_DRAW); + st.ownAttribute(verticeFboAttr, true); + + + indicesTxt = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialSize, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER); + + verticeTxtAttr = GLArrayDataServer.createGLSL(st, AttributeNames.VERTEX_ATTR_NAME, 3, + GL2ES2.GL_FLOAT, false, initialSize, GL.GL_STATIC_DRAW); + st.ownAttribute(verticeTxtAttr, true); + + texCoordTxtAttr = GLArrayDataServer.createGLSL(st, AttributeNames.TEXCOORD_ATTR_NAME, 2, + GL2ES2.GL_FLOAT, false, initialSize, 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(Triangle t:triangles){ - if(t.getVertices()[0].getId() == Integer.MAX_VALUE){ - t.getVertices()[0].setId(numVertices++); - t.getVertices()[1].setId(numVertices++); - t.getVertices()[2].setId(numVertices++); + for(int i=0; i "+tex_height_c+"x"+tex_width_c); // System.out.println("FBO Scale: " + m.glGetMatrixf().get(0) +" " + m.glGetMatrixf().get(5)); @@ -283,6 +266,17 @@ public class VBORegion2PES2 implements Region { 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) { @@ -297,25 +291,6 @@ public class VBORegion2PES2 implements Region { indicesTxt.enableBuffer(gl, false); } - public void addTriangles(ArrayList tris) { - triangles.addAll(tris); - dirty = true; - } - - public int getNumVertices(){ - return numVertices; - } - - public void addVertices(ArrayList verts){ - vertices.addAll(verts); - numVertices = vertices.size(); - dirty = true; - } - - public boolean isDirty(){ - return dirty; - } - public void destroy(GL2ES2 gl, RenderState rs) { if(DEBUG_INSTANCE) { System.err.println("VBORegion2PES2 Destroy: " + this); @@ -355,17 +330,5 @@ public class VBORegion2PES2 implements Region { } triangles.clear(); vertices.clear(); - } - - public boolean isFlipped() { - return flipped; - } - - public void setFlipped(boolean flipped) { - this.flipped = flipped; - } - - public AABBox getBounds(){ - return box; - } + } } diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java index 7956e5137..17fb29b1b 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java @@ -27,14 +27,12 @@ */ package jogamp.graph.curve.opengl; -import java.util.ArrayList; - import javax.media.opengl.GL; import javax.media.opengl.GL2ES2; 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.RenderState; import com.jogamp.graph.geom.AABBox; import com.jogamp.graph.geom.Vertex; @@ -42,50 +40,44 @@ import com.jogamp.graph.geom.Triangle; import com.jogamp.opengl.util.GLArrayDataServer; import com.jogamp.opengl.util.glsl.ShaderState; -public class VBORegionSPES2 implements Region { - private int numVertices = 0; - - private ArrayList triangles = new ArrayList(); - private ArrayList vertices = new ArrayList(); +public class VBORegionSPES2 extends GLRegion { private GLArrayDataServer verticeAttr = null; private GLArrayDataServer texCoordAttr = null; private GLArrayDataServer indices = null; - - private boolean flipped = false; - private boolean dirty = true; - - private AABBox box = null; - - public VBORegionSPES2(RenderState rs){ - box = new AABBox(); - final int initialSize = 256; - final ShaderState st = rs.getShaderState(); - - indices = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialSize, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER); - - verticeAttr = GLArrayDataServer.createGLSL(st, AttributeNames.VERTEX_ATTR_NAME, 3, - GL2ES2.GL_FLOAT, false, initialSize, GL.GL_STATIC_DRAW); - st.ownAttribute(verticeAttr, true); - - texCoordAttr = GLArrayDataServer.createGLSL(st, AttributeNames.TEXCOORD_ATTR_NAME, 2, - GL2ES2.GL_FLOAT, false, initialSize, GL.GL_STATIC_DRAW); - st.ownAttribute(texCoordAttr, true); - - if(DEBUG_INSTANCE) { - System.err.println("VBORegionSPES2 Create: " + this); - } + protected VBORegionSPES2(int renderModes) { + super(renderModes); } - public void update(GL2ES2 gl){ - if(!dirty) { + protected void update(GL2ES2 gl, RenderState rs) { + if(!isDirty()) { return; } + if(null == indices) { + final int initialSize = 256; + final ShaderState st = rs.getShaderState(); + + indices = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialSize, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER); + + verticeAttr = GLArrayDataServer.createGLSL(st, AttributeNames.VERTEX_ATTR_NAME, 3, + GL2ES2.GL_FLOAT, false, initialSize, GL.GL_STATIC_DRAW); + st.ownAttribute(verticeAttr, true); + + texCoordAttr = GLArrayDataServer.createGLSL(st, AttributeNames.TEXCOORD_ATTR_NAME, 2, + GL2ES2.GL_FLOAT, false, initialSize, GL.GL_STATIC_DRAW); + st.ownAttribute(texCoordAttr, true); + + if(DEBUG_INSTANCE) { + System.err.println("VBORegionSPES2 Create: " + this); + } + } + // process triangles indices.seal(gl, false); indices.rewind(); - for(Triangle t:triangles){ + for(int i=0; i tris) { - triangles.addAll(tris); - dirty = true; - } - - public int getNumVertices(){ - return numVertices; - } - - public void addVertices(ArrayList verts){ - vertices.addAll(verts); - numVertices = vertices.size(); - dirty = true; - } - - public boolean isDirty(){ - return dirty; - } + } public final void destroy(GL2ES2 gl, RenderState rs) { if(DEBUG_INSTANCE) { @@ -206,16 +162,5 @@ public class VBORegionSPES2 implements Region { indices.destroy(gl); indices = null; } - } - - public boolean isFlipped() { - return flipped; - } - - public void setFlipped(boolean flipped) { - this.flipped = flipped; - } - public AABBox getBounds(){ - return box; - } + } } -- cgit v1.2.3