diff options
Diffstat (limited to 'src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java')
-rw-r--r-- | src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java | 368 |
1 files changed, 184 insertions, 184 deletions
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java index 81d9d1858..05814965e 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java @@ -49,35 +49,35 @@ import com.jogamp.opengl.util.glsl.ShaderState; public class VBORegion2PES2 implements Region { private int numVertices = 0; - private ArrayList<Triangle> triangles = new ArrayList<Triangle>(); - private ArrayList<Vertex> vertices = new ArrayList<Vertex>(); - private GLArrayDataServer verticeTxtAttr = null; - private GLArrayDataServer texCoordTxtAttr = null; - private GLArrayDataServer indicesTxt = null; + private ArrayList<Triangle> triangles = new ArrayList<Triangle>(); + private ArrayList<Vertex> vertices = new ArrayList<Vertex>(); + private GLArrayDataServer verticeTxtAttr = null; + private GLArrayDataServer texCoordTxtAttr = null; + private GLArrayDataServer indicesTxt = null; private GLArrayDataServer verticeFboAttr = null; private GLArrayDataServer texCoordFboAttr = null; private GLArrayDataServer indicesFbo = null; - - private GLContext context; - - private boolean flipped = false; - - private boolean dirty = false; - - private AABBox box = null; - private FBObject fbo = null; + + private GLContext context; + + private boolean flipped = false; + + private boolean dirty = false; + + private AABBox box = null; + private FBObject fbo = null; - private int tex_width_c = 0; - private int tex_height_c = 0; - - private ShaderState st; - - public VBORegion2PES2(GLContext context, ShaderState st){ - this.context =context; - this.st = st; - - GL2ES2 gl = context.getGL().getGL2ES2(); - + private int tex_width_c = 0; + private int tex_height_c = 0; + + private ShaderState st; + + public VBORegion2PES2(GLContext context, ShaderState st){ + this.context =context; + this.st = st; + + GL2ES2 gl = context.getGL().getGL2ES2(); + indicesFbo = GLArrayDataServer.createGLSL(gl, null, 3, GL2ES2.GL_SHORT, false, 2, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER); indicesFbo.puts((short) 0); indicesFbo.puts((short) 1); indicesFbo.puts((short) 3); @@ -108,132 +108,132 @@ public class VBORegion2PES2 implements Region { if(DEBUG) { System.err.println("VBORegion2PES2 Create: " + this); } - } - - public void update(){ - GL2ES2 gl = context.getGL().getGL2ES2(); - + } + + public void update(){ + GL2ES2 gl = context.getGL().getGL2ES2(); + destroyTxtAttr(gl); box = new AABBox(); indicesTxt = GLArrayDataServer.createGLSL(gl, null, 3, GL2ES2.GL_SHORT, false, triangles.size(), GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER); - 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++); - - vertices.add(t.getVertices()[0]); - vertices.add(t.getVertices()[1]); - vertices.add(t.getVertices()[2]); - - indicesTxt.puts((short) t.getVertices()[0].getId()); - indicesTxt.puts((short) t.getVertices()[1].getId()); - indicesTxt.puts((short) t.getVertices()[2].getId()); - } - else{ - Vertex v1 = t.getVertices()[0]; - Vertex v2 = t.getVertices()[1]; - Vertex v3 = t.getVertices()[2]; - - indicesTxt.puts((short) v1.getId()); - indicesTxt.puts((short) v2.getId()); - indicesTxt.puts((short) v3.getId()); - } - } + 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++); + + vertices.add(t.getVertices()[0]); + vertices.add(t.getVertices()[1]); + vertices.add(t.getVertices()[2]); + + indicesTxt.puts((short) t.getVertices()[0].getId()); + indicesTxt.puts((short) t.getVertices()[1].getId()); + indicesTxt.puts((short) t.getVertices()[2].getId()); + } + else{ + Vertex v1 = t.getVertices()[0]; + Vertex v2 = t.getVertices()[1]; + Vertex v3 = t.getVertices()[2]; + + indicesTxt.puts((short) v1.getId()); + indicesTxt.puts((short) v2.getId()); + indicesTxt.puts((short) v3.getId()); + } + } indicesTxt.seal(gl, true); verticeTxtAttr = GLArrayDataServer.createGLSL(gl, Region.VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT, false, vertices.size(), GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER); verticeTxtAttr.setLocation(Region.VERTEX_ATTR_IDX); - for(Vertex v:vertices){ - verticeTxtAttr.putf(v.getX()); - if(flipped){ - verticeTxtAttr.putf(-1*v.getY()); - } else { - verticeTxtAttr.putf(v.getY()); - } - verticeTxtAttr.putf(v.getZ()); - if(flipped){ - box.resize(v.getX(), -1*v.getY(), v.getZ()); - } else { - box.resize(v.getX(), v.getY(), v.getZ()); - } - } + for(Vertex v:vertices){ + verticeTxtAttr.putf(v.getX()); + if(flipped){ + verticeTxtAttr.putf(-1*v.getY()); + } else { + verticeTxtAttr.putf(v.getY()); + } + verticeTxtAttr.putf(v.getZ()); + if(flipped){ + box.resize(v.getX(), -1*v.getY(), v.getZ()); + } else { + box.resize(v.getX(), v.getY(), v.getZ()); + } + } verticeTxtAttr.seal(gl, true); - + texCoordTxtAttr = GLArrayDataServer.createGLSL(gl, Region.TEXCOORD_ATTR_NAME, 2, GL2ES2.GL_FLOAT, false, vertices.size(), GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER); texCoordTxtAttr.setLocation(Region.TEXCOORD_ATTR_IDX); - for(Vertex v:vertices){ - float[] tex = v.getTexCoord(); - texCoordTxtAttr.putf(tex[0]); - texCoordTxtAttr.putf(tex[1]); - } + for(Vertex v:vertices){ + float[] tex = v.getTexCoord(); + texCoordTxtAttr.putf(tex[0]); + texCoordTxtAttr.putf(tex[1]); + } texCoordTxtAttr.seal(gl, true); // leave the buffers enabled for subsequent render call - dirty = false; - } - - public void render(PMVMatrix matrix, int vp_width, int vp_height, int width){ + dirty = false; + } + + public void render(PMVMatrix matrix, int vp_width, int vp_height, int width){ GL2ES2 gl = context.getGL().getGL2ES2(); - if(null == matrix || vp_width <=0 || vp_height <= 0 || width <= 0){ - renderRegion(gl); - } else { - if(width != tex_width_c){ + if(null == matrix || vp_width <=0 || vp_height <= 0 || width <= 0){ + renderRegion(gl); + } else { + if(width != tex_width_c){ renderRegion2FBO(gl, matrix, width); setupBBox2FboAttr(gl); - } -// System.out.println("Scale: " + matrix.glGetMatrixf().get(1+4*3) +" " + matrix.glGetMatrixf().get(2+4*3)); - renderFBO(gl, matrix, vp_width, vp_height); - } - } - - private void renderFBO(GL2ES2 gl, PMVMatrix matrix, int width, int hight) { - gl.glViewport(0, 0, width, hight); - if(!st.glUniform(gl, new GLUniformData("mgl_PMVMatrix", 4, 4, matrix.glGetPMvMatrixf()))){ - System.out.println("Cnt set tex based mat"); - } - gl.glEnable(GL2ES2.GL_TEXTURE_2D); - gl.glActiveTexture(GL2ES2.GL_TEXTURE0); - fbo.use(gl); - - st.glUniform(gl, new GLUniformData("texture", fbo.getTextureName())); - int loc = gl.glGetUniformLocation(st.shaderProgram().program(), "texture"); - gl.glUniform1i(loc, 0); - - + } +// System.out.println("Scale: " + matrix.glGetMatrixf().get(1+4*3) +" " + matrix.glGetMatrixf().get(2+4*3)); + renderFBO(gl, matrix, vp_width, vp_height); + } + } + + private void renderFBO(GL2ES2 gl, PMVMatrix matrix, int width, int hight) { + gl.glViewport(0, 0, width, hight); + if(!st.glUniform(gl, new GLUniformData("mgl_PMVMatrix", 4, 4, matrix.glGetPMvMatrixf()))){ + System.out.println("Cnt set tex based mat"); + } + gl.glEnable(GL2ES2.GL_TEXTURE_2D); + gl.glActiveTexture(GL2ES2.GL_TEXTURE0); + fbo.use(gl); + + st.glUniform(gl, new GLUniformData("texture", fbo.getTextureName())); + int loc = gl.glGetUniformLocation(st.shaderProgram().program(), "texture"); + gl.glUniform1i(loc, 0); + + verticeFboAttr.enableBuffer(gl, true); texCoordFboAttr.enableBuffer(gl, true); indicesFbo.enableBuffer(gl, true); gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesFbo.getElementNumber() * indicesFbo.getComponentNumber(), GL2ES2.GL_UNSIGNED_SHORT, 0); - + verticeFboAttr.enableBuffer(gl, false); texCoordFboAttr.enableBuffer(gl, false); indicesFbo.enableBuffer(gl, false); - } - - private void setupBBox2FboAttr(GL2ES2 gl){ + } + + private void setupBBox2FboAttr(GL2ES2 gl){ 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.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); - } - - private void renderRegion2FBO(GL2ES2 gl, PMVMatrix m, int tex_width){ - tex_width_c = tex_width; - tex_height_c = (int)(tex_width_c*box.getHeight()/box.getWidth()); - + } + + private void renderRegion2FBO(GL2ES2 gl, PMVMatrix m, int tex_width){ + tex_width_c = tex_width; + tex_height_c = (int)(tex_width_c*box.getHeight()/box.getWidth()); + // System.out.println("FBO Size: "+tex_width+" -> "+tex_height_c+"x"+tex_width_c); // System.out.println("FBO Scale: " + m.glGetMatrixf().get(0) +" " + m.glGetMatrixf().get(5)); @@ -245,79 +245,79 @@ public class VBORegion2PES2 implements Region { if(null == fbo) { fbo = new FBObject(tex_width_c, tex_height_c); // FIXME: shall not use bilinear, due to own AA ? However, w/o bilinear result is not smooth - fbo.init(gl, GL2ES2.GL_LINEAR, GL2ES2.GL_LINEAR, GL2ES2.GL_CLAMP_TO_EDGE, GL2ES2.GL_CLAMP_TO_EDGE); - // fbo.init(gl, GL2ES2.GL_NEAREST, GL2ES2.GL_NEAREST, GL2ES2.GL_CLAMP_TO_EDGE, GL2ES2.GL_CLAMP_TO_EDGE); - fbo.attachDepthBuffer(gl, GL.GL_DEPTH_COMPONENT16); // FIXME: or shall we use 24 or 32 bit depth ? + fbo.init(gl, GL2ES2.GL_LINEAR, GL2ES2.GL_LINEAR, GL2ES2.GL_CLAMP_TO_EDGE, GL2ES2.GL_CLAMP_TO_EDGE); + // fbo.init(gl, GL2ES2.GL_NEAREST, GL2ES2.GL_NEAREST, GL2ES2.GL_CLAMP_TO_EDGE, GL2ES2.GL_CLAMP_TO_EDGE); + fbo.attachDepthBuffer(gl, GL.GL_DEPTH_COMPONENT16); // FIXME: or shall we use 24 or 32 bit depth ? } else { fbo.bind(gl); } - - //render texture - PMVMatrix tex_matrix = new PMVMatrix(); - gl.glViewport(0, 0, tex_width_c, tex_height_c); - tex_matrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION); - tex_matrix.glLoadIdentity(); - tex_matrix.glOrthof(box.getLow()[0], box.getHigh()[0], box.getLow()[1], box.getHigh()[1], -1, 1); - - if(!st.glUniform(gl, new GLUniformData("mgl_PMVMatrix", 4, 4, tex_matrix.glGetPMvMatrixf()))){ - System.out.println("Cnt set tex based mat"); - } - - gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); - gl.glClear(GL2ES2.GL_COLOR_BUFFER_BIT | GL2ES2.GL_DEPTH_BUFFER_BIT); - renderRegion(gl); + + //render texture + PMVMatrix tex_matrix = new PMVMatrix(); + gl.glViewport(0, 0, tex_width_c, tex_height_c); + tex_matrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION); + tex_matrix.glLoadIdentity(); + tex_matrix.glOrthof(box.getLow()[0], box.getHigh()[0], box.getLow()[1], box.getHigh()[1], -1, 1); + + if(!st.glUniform(gl, new GLUniformData("mgl_PMVMatrix", 4, 4, tex_matrix.glGetPMvMatrixf()))){ + System.out.println("Cnt set tex based mat"); + } + + 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); - } - - private void renderRegion(GL2ES2 gl) { + fbo.unbind(gl); + } + + private void renderRegion(GL2ES2 gl) { verticeTxtAttr.enableBuffer(gl, true); texCoordTxtAttr.enableBuffer(gl, true); indicesTxt.enableBuffer(gl, true); - - gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesTxt.getElementNumber() * indicesTxt.getComponentNumber(), GL2ES2.GL_UNSIGNED_SHORT, 0); - + + gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesTxt.getElementNumber() * indicesTxt.getComponentNumber(), GL2ES2.GL_UNSIGNED_SHORT, 0); + verticeTxtAttr.enableBuffer(gl, false); texCoordTxtAttr.enableBuffer(gl, false); indicesTxt.enableBuffer(gl, false); - } - - public void addTriangles(ArrayList<Triangle> tris) { - triangles.addAll(tris); - dirty = true; - } - - public int getNumVertices(){ - return numVertices; - } - - public void addVertices(ArrayList<Vertex> verts){ - vertices.addAll(verts); - numVertices = vertices.size(); - dirty = true; - } - - public boolean isDirty(){ - return dirty; - } - - public void destroy() { - if(DEBUG) { - System.err.println("VBORegion2PES2 Destroy: " + this); - } - GL2ES2 gl = context.getGL().getGL2ES2(); - destroyFbo(gl); + } + + public void addTriangles(ArrayList<Triangle> tris) { + triangles.addAll(tris); + dirty = true; + } + + public int getNumVertices(){ + return numVertices; + } + + public void addVertices(ArrayList<Vertex> verts){ + vertices.addAll(verts); + numVertices = vertices.size(); + dirty = true; + } + + public boolean isDirty(){ + return dirty; + } + + public void destroy() { + if(DEBUG) { + System.err.println("VBORegion2PES2 Destroy: " + this); + } + GL2ES2 gl = context.getGL().getGL2ES2(); + destroyFbo(gl); destroyTxtAttr(gl); destroyFboAttr(gl); triangles.clear(); vertices.clear(); - } - final void destroyFbo(GL2ES2 gl) { + } + final void destroyFbo(GL2ES2 gl) { if(null != fbo) { fbo.destroy(gl); fbo = null; - } - } + } + } final void destroyTxtAttr(GL2ES2 gl) { if(null != verticeTxtAttr) { verticeTxtAttr.destroy(gl); @@ -331,7 +331,7 @@ public class VBORegion2PES2 implements Region { indicesTxt.destroy(gl); indicesTxt = null; } - } + } final void destroyFboAttr(GL2ES2 gl) { if(null != verticeFboAttr) { verticeFboAttr.destroy(gl); @@ -347,15 +347,15 @@ public class VBORegion2PES2 implements Region { } } - public boolean isFlipped() { - return flipped; - } + public boolean isFlipped() { + return flipped; + } - public void setFlipped(boolean flipped) { - this.flipped = flipped; - } - - public AABBox getBounds(){ - return box; - } + public void setFlipped(boolean flipped) { + this.flipped = flipped; + } + + public AABBox getBounds(){ + return box; + } } |