diff options
author | Sven Gothel <[email protected]> | 2011-04-01 06:48:52 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-04-01 06:48:52 +0200 |
commit | 4b8bd5ec58cb2edfb51bd9ee930beb9c539a8a0b (patch) | |
tree | 5567f56606ea248707fe002015b90a9635250e91 | |
parent | e8c69e69374b6650e37594ebf104602fb06b548b (diff) |
Final core and demo changes for jogl merge
Core:
- Region: Cleanup up constant names
- Renderer: Add getRenderType()
- TextRenderer: Add cache size limit
- JavaFontLoader: Add FIXME 'Add cache size to limit memory usage'
- UbuntuFontLoader: Add cache and FIXME 'Add cache size to limit memory usage'
- TypecastFont: Add FIXME 'Add cache size to limit memory usage ??'
Demos:
- Relocated and split (main/listener) for jogl merge
- Add 's' for screenshot
- Text:
- Add 'i' for live editing mode (until CR, backspace supported)
27 files changed, 700 insertions, 534 deletions
diff --git a/src/com/jogamp/graph/curve/Region.java b/src/com/jogamp/graph/curve/Region.java index 5c4e8dad1..051cb1c38 100755 --- a/src/com/jogamp/graph/curve/Region.java +++ b/src/com/jogamp/graph/curve/Region.java @@ -46,14 +46,17 @@ import com.jogamp.opengl.util.PMVMatrix; public interface Region {
/** The vertices index in an OGL object
*/
- public static int VERTEX_POS_INDX = 0;
+ public static int VERTEX_ATTR_IDX = 0;
/** The Texture Coord index in an OGL object
*/
- public static int TEX_COORD = 1;
+ public static int TEXCOORD_ATTR_IDX = 1;
- public static int SINGLE_PASS = 10;
- public static int TWO_PASS = 20;
+ /** single pass rendering, fast, but AA might not be perfect */
+ public static int SINGLE_PASS = 1;
+
+ /** two pass rendering, slower and more resource hungry (FBO), but AA is perfect */
+ public static int TWO_PASS = 2;
/** Updates a graph region by updating the ogl related
* objects for use in rendering. if called for the first time
diff --git a/src/com/jogamp/graph/curve/opengl/RegionRenderer.java b/src/com/jogamp/graph/curve/opengl/RegionRenderer.java index 746eba636..c1fec10b8 100644 --- a/src/com/jogamp/graph/curve/opengl/RegionRenderer.java +++ b/src/com/jogamp/graph/curve/opengl/RegionRenderer.java @@ -59,7 +59,7 @@ public abstract class RegionRenderer extends Renderer { * @return the resulting Region. */ protected Region createRegion(GL2ES2 gl, OutlineShape outlineShape, float sharpness) { - Region region = RegionFactory.create(gl.getContext(), st, regionType); + Region region = RegionFactory.create(gl.getContext(), st, renderType); outlineShape.transformOutlines(OutlineShape.QUADRATIC_NURBS); @@ -78,7 +78,7 @@ public abstract class RegionRenderer extends Renderer { * @return the resulting Region inclusive the generated region */ protected Region createRegion(GL2ES2 gl, OutlineShape[] outlineShapes, float sharpness) { - Region region = RegionFactory.create(gl.getContext(), st, regionType); + Region region = RegionFactory.create(gl.getContext(), st, renderType); int numVertices = region.getNumVertices(); diff --git a/src/com/jogamp/graph/curve/opengl/Renderer.java b/src/com/jogamp/graph/curve/opengl/Renderer.java index a36cf870b..863928ed4 100644 --- a/src/com/jogamp/graph/curve/opengl/Renderer.java +++ b/src/com/jogamp/graph/curve/opengl/Renderer.java @@ -6,7 +6,6 @@ import javax.media.opengl.fixedfunc.GLMatrixFunc; import jogamp.opengl.Debug; -import com.jogamp.graph.curve.Region; import com.jogamp.graph.geom.Vertex; import com.jogamp.graph.geom.opengl.SVertex; import com.jogamp.opengl.util.PMVMatrix; @@ -34,15 +33,20 @@ public abstract class Renderer { protected ShaderState st = new ShaderState(); protected PMVMatrix pmvMatrix = new PMVMatrix(); protected GLUniformData mgl_PMVMatrix; - protected int regionType = Region.SINGLE_PASS; + protected int renderType; protected int vp_width = 0; protected int vp_height = 0; private boolean vboSupported = false; private boolean initialized = false; - protected Renderer(Vertex.Factory<? extends Vertex> factory, int type) { - this.regionType = type; + /** + * + * @param factory + * @param renderType either {@link com.jogamp.graph.curve.Region#SINGLE_PASS} or {@link com.jogamp.graph.curve.Region#TWO_PASS} + */ + protected Renderer(Vertex.Factory<? extends Vertex> factory, int renderType) { + this.renderType = renderType; this.pointFactory = (null != factory) ? factory : SVertex.factory(); } @@ -52,6 +56,8 @@ public abstract class Renderer { public final boolean isVBOSupported() { return vboSupported; } + public final int getRenderType() { return renderType; } + public final int getWidth() { return vp_width; } public final int getHeight() { return vp_height; } diff --git a/src/com/jogamp/graph/curve/opengl/TextRenderer.java b/src/com/jogamp/graph/curve/opengl/TextRenderer.java index 83f2c93ca..2bb99d27c 100644 --- a/src/com/jogamp/graph/curve/opengl/TextRenderer.java +++ b/src/com/jogamp/graph/curve/opengl/TextRenderer.java @@ -1,5 +1,6 @@ package com.jogamp.graph.curve.opengl; +import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -15,8 +16,6 @@ import com.jogamp.graph.geom.Vertex; public abstract class TextRenderer extends Renderer { - protected HashMap<String, GlyphString> strings = new HashMap<String, GlyphString>(); - /** * Create a Hardware accelerated Text Renderer. * @param factory optional Point.Factory for Vertex construction. Default is Vertex.Factory. @@ -58,22 +57,47 @@ public abstract class TextRenderer extends Renderer { GlyphString glyphString = new GlyphString(pointFactory, font.getName(), str); glyphString.createfromFontPath(paths, affineTransform); - glyphString.generateRegion(gl.getContext(), sharpness, st, regionType); + glyphString.generateRegion(gl.getContext(), sharpness, st, renderType); return glyphString; } - protected static String getTextHashCode(Font font, String str, int fontSize) { - // FIXME: use integer hash code - return font.getName() + "." + str.hashCode() + "." + fontSize; - } - public void flushCache() { - Iterator<GlyphString> iterator = strings.values().iterator(); + Iterator<GlyphString> iterator = stringCacheMap.values().iterator(); while(iterator.hasNext()){ GlyphString glyphString = iterator.next(); glyphString.destroy(); } - strings.clear(); - } + stringCacheMap.clear(); + stringCacheArray.clear(); + } + + public final void setCacheMaxSize(int newSize ) { stringCacheMaxSize = newSize; validateCache(0); } + public final int getCacheMaxSize() { return stringCacheMaxSize; } + public final int getCacheSize() { return stringCacheArray.size(); } + + protected void validateCache(int space) { + while ( getCacheSize() + space > getCacheMaxSize() ) { + String key = stringCacheArray.remove(0); + stringCacheMap.remove(key); + } + } + + protected GlyphString getCachedGlyphString(Font font, String str, int fontSize) { + final String key = font.getName() + "." + str.hashCode() + "." + fontSize; + return stringCacheMap.get(key); + } + + protected void addCachedGlyphString(Font font, String str, int fontSize, GlyphString glyphString) { + final String key = font.getName() + "." + str.hashCode() + "." + fontSize; + validateCache(1); + stringCacheMap.put(key, glyphString); + stringCacheArray.add(stringCacheArray.size(), key); + } + + // Cache is adding at the end of the array + public static final int DEFAULT_CACHE_SIZE = 32; + private HashMap<String, GlyphString> stringCacheMap = new HashMap<String, GlyphString>(DEFAULT_CACHE_SIZE); + private ArrayList<String> stringCacheArray = new ArrayList<String>(DEFAULT_CACHE_SIZE); + private int stringCacheMaxSize = DEFAULT_CACHE_SIZE; // -1 unlimited, 0 off, >0 limited }
\ No newline at end of file diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestRegionRenderer01.java b/src/com/jogamp/opengl/test/junit/graph/TestRegionRenderer01.java index 52892e646..9ad4eb41a 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/TestRegionRenderer01.java +++ b/src/com/jogamp/opengl/test/junit/graph/TestRegionRenderer01.java @@ -1,4 +1,4 @@ -package test.com.jogamp.opengl.test.junit.graph;
+package com.jogamp.opengl.test.junit.graph;
import java.io.IOException;
@@ -14,11 +14,12 @@ import org.junit.Assert; import org.junit.BeforeClass;
import org.junit.Test;
+import com.jogamp.graph.curve.Region;
import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.opengl.test.junit.graph.demos.GPURegionGLListener01;
+import com.jogamp.opengl.test.junit.graph.demos.GPURegionGLListener02;
+import com.jogamp.opengl.test.junit.graph.demos.GPURegionRendererListenerBase01;
-import demo.GPURegionNewtDemo01;
-import demo.GPURegionNewtDemo02;
-import demo.GPURegionRendererListenerBase01;
public class TestRegionRenderer01 {
@@ -54,15 +55,17 @@ public class TestRegionRenderer01 { @Test
public void testRegionRendererR2T01() throws InterruptedException {
- GLProfile glp = GLProfile.get(GLProfile.GL3);
+ GLProfile glp = GLProfile.getGL2ES2();
+
GLCapabilities caps = new GLCapabilities(glp);
//caps.setOnscreen(false);
caps.setAlphaBits(4);
GLWindow window = createWindow("shape-r2t1-msaa0", caps, 800,400);
- GPURegionNewtDemo02 demo02 = new GPURegionNewtDemo02();
- GPURegionNewtDemo02.RegionGLListener demo02Listener = demo02.createRegionRendererListener(window);
+ GPURegionGLListener02 demo02Listener = new GPURegionGLListener02 (Region.TWO_PASS, 1140, false, false);
+ demo02Listener.attachInputListenerTo(window);
+ window.addGLEventListener(demo02Listener);
RegionGLListener listener = new RegionGLListener(demo02Listener, window.getTitle(), "GPURegionNewtDemo02");
window.addGLEventListener(listener);
@@ -90,10 +93,11 @@ public class TestRegionRenderer01 { GLWindow window = createWindow("shape-r2t0-msaa1", caps, 800, 400);
- GPURegionNewtDemo01 demo01 = new GPURegionNewtDemo01();
- GPURegionNewtDemo01.RegionGLListener demo01Listener = demo01.createRegionRendererListener(window);
-
- RegionGLListener listener = new RegionGLListener(demo01Listener, window.getTitle(), "GPURegionNewtDemo01");
+ GPURegionGLListener01 demo01Listener = new GPURegionGLListener01 (Region.SINGLE_PASS, 0, false, false);
+ demo01Listener.attachInputListenerTo(window);
+ window.addGLEventListener(demo01Listener);
+
+ RegionGLListener listener = new RegionGLListener(demo01Listener, window.getTitle(), "GPURegion01");
window.addGLEventListener(listener);
listener.setTech(-20, 00, 0f, -300, 400);
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRenderer01.java b/src/com/jogamp/opengl/test/junit/graph/TestTextRenderer01.java index acfde7e1f..c954c6aa7 100755 --- a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRenderer01.java +++ b/src/com/jogamp/opengl/test/junit/graph/TestTextRenderer01.java @@ -1,4 +1,4 @@ -package test.com.jogamp.opengl.test.junit.graph;
+package com.jogamp.opengl.test.junit.graph;
import java.io.IOException;
@@ -20,13 +20,13 @@ import com.jogamp.graph.curve.opengl.TextRenderer; import com.jogamp.graph.font.FontFactory;
import com.jogamp.graph.geom.opengl.SVertex;
import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.opengl.test.junit.graph.demos.GPUTextRendererListenerBase01;
-import demo.GPUTextRendererListenerBase01;
public class TestTextRenderer01 {
public static void main(String args[]) throws IOException {
- String tstname = TestRegionRenderer01.class.getName();
+ String tstname = TestTextRenderer01.class.getName();
org.junit.runner.JUnitCore.main(tstname);
}
@@ -57,7 +57,8 @@ public class TestTextRenderer01 { @Test
public void testTextRendererR2T01() throws InterruptedException {
- GLProfile glp = GLProfile.get(GLProfile.GL3);
+ GLProfile glp = GLProfile.getGL2ES2();
+
GLCapabilities caps = new GLCapabilities(glp);
caps.setAlphaBits(4);
@@ -67,23 +68,23 @@ public class TestTextRenderer01 { window.addGLEventListener(textGLListener);
textGLListener.setFontSet(FontFactory.UBUNTU, 0, 0);
- textGLListener.setTech(-400, -30, 0f, -1000, 400);
+ textGLListener.setTech(-400, -30, 0f, -1000, window.getWidth()*2);
window.display();
- textGLListener.setTech(-400, -30, 0, -380, 1100);
+ textGLListener.setTech(-400, -30, 0, -380, window.getWidth()*3);
window.display();
- textGLListener.setTech(-400, -20, 0, -80, 2500);
+ textGLListener.setTech(-400, -20, 0, -80, window.getWidth()*4);
window.display();
textGLListener.setFontSet(FontFactory.JAVA, 0, 0);
- textGLListener.setTech(-400, -30, 0f, -1000, 400);
+ textGLListener.setTech(-400, -30, 0f, -1000, window.getWidth()*2);
window.display();
- textGLListener.setTech(-400, -30, 0, -380, 1100);
+ textGLListener.setTech(-400, -30, 0, -380, window.getWidth()*3);
window.display();
- textGLListener.setTech(-400, -20, 0, -80, 2500);
+ textGLListener.setTech(-400, -20, 0, -80, window.getWidth()*4);
window.display();
destroyWindow(window);
diff --git a/src/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener01.java b/src/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener01.java new file mode 100644 index 000000000..bf4bfab71 --- /dev/null +++ b/src/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener01.java @@ -0,0 +1,124 @@ +/** + * 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 com.jogamp.opengl.test.junit.graph.demos; + +import javax.media.opengl.GL; +import javax.media.opengl.GL2ES2; +import javax.media.opengl.GLAutoDrawable; +import com.jogamp.graph.curve.OutlineShape; +import com.jogamp.graph.curve.opengl.RegionRenderer; +import com.jogamp.graph.geom.opengl.SVertex; + +/** Demonstrate the rendering of multiple outlines into one region/OutlineShape + * These Outlines are not necessary connected or contained. + * The output of this demo shows two identical shapes but the left one + * has some vertices with off-curve flag set to true, and the right allt he vertices + * are on the curve. Demos the Res. Independent Nurbs based Curve rendering + * + */ +public class GPURegionGLListener01 extends GPURegionRendererListenerBase01 { + OutlineShape outlineShape = null; + + public GPURegionGLListener01 (int numpass, int fbosize, boolean debug, boolean trace) { + super(SVertex.factory(), numpass, debug, trace); + setMatrix(-20, 00, 0f, -50, fbosize); + } + + private void createTestOutline(){ + float offset = 0; + outlineShape = new OutlineShape(getRenderer().getFactory()); + outlineShape.addVertex(0.0f,-10.0f, true); + outlineShape.addVertex(15.0f,-10.0f, true); + outlineShape.addVertex(10.0f,5.0f, false); + outlineShape.addVertex(15.0f,10.0f, true); + outlineShape.addVertex(6.0f,15.0f, false); + outlineShape.addVertex(5.0f,8.0f, false); + outlineShape.addVertex(0.0f,10.0f,true); + outlineShape.closeLastOutline(); + outlineShape.addEmptyOutline(); + outlineShape.addVertex(5.0f,-5.0f,true); + outlineShape.addVertex(10.0f,-5.0f, false); + outlineShape.addVertex(10.0f,0.0f, true); + outlineShape.addVertex(5.0f,0.0f, false); + outlineShape.closeLastOutline(); + + /** Same shape as above but without any off-curve vertices */ + outlineShape.addEmptyOutline(); + offset = 30; + outlineShape.addVertex(offset+0.0f,-10.0f, true); + outlineShape.addVertex(offset+17.0f,-10.0f, true); + outlineShape.addVertex(offset+11.0f,5.0f, true); + outlineShape.addVertex(offset+16.0f,10.0f, true); + outlineShape.addVertex(offset+7.0f,15.0f, true); + outlineShape.addVertex(offset+6.0f,8.0f, true); + outlineShape.addVertex(offset+0.0f,10.0f, true); + outlineShape.closeLastOutline(); + outlineShape.addEmptyOutline(); + outlineShape.addVertex(offset+5.0f,0.0f, true); + outlineShape.addVertex(offset+5.0f,-5.0f, true); + outlineShape.addVertex(offset+10.0f,-5.0f, true); + outlineShape.addVertex(offset+10.0f,0.0f, true); + outlineShape.closeLastOutline(); + } + + public void init(GLAutoDrawable drawable) { + super.init(drawable); + + GL2ES2 gl = drawable.getGL().getGL2ES2(); + + final RegionRenderer regionRenderer = (RegionRenderer) getRenderer(); + + gl.setSwapInterval(1); + gl.glEnable(GL2ES2.GL_DEPTH_TEST); + regionRenderer.init(gl); + regionRenderer.setAlpha(gl, 1.0f); + regionRenderer.setColor(gl, 0.0f, 0.0f, 0.0f); + //gl.glSampleCoverage(0.95f, false); + //gl.glEnable(GL2GL3.GL_SAMPLE_COVERAGE); // sample coverage doesn't really make a difference to lines + //gl.glEnable(GL2GL3.GL_SAMPLE_ALPHA_TO_ONE); + MSAATool.dump(drawable); + + createTestOutline(); + } + + public void display(GLAutoDrawable drawable) { + GL2ES2 gl = drawable.getGL().getGL2ES2(); + + gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); + gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); + + final RegionRenderer regionRenderer = (RegionRenderer) getRenderer(); + + regionRenderer.resetModelview(null); + regionRenderer.translate(null, getXTran(), getYTran(), getZoom()); + regionRenderer.rotate(gl, getAngle(), 0, 1, 0); + + regionRenderer.renderOutlineShape(gl, outlineShape, getPosition(), getTexSize()); + } +} diff --git a/src/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener02.java b/src/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener02.java new file mode 100644 index 000000000..56db37ebe --- /dev/null +++ b/src/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener02.java @@ -0,0 +1,120 @@ +/** + * 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 com.jogamp.opengl.test.junit.graph.demos; + +import javax.media.opengl.GL; +import javax.media.opengl.GL2ES2; +import javax.media.opengl.GLAutoDrawable; + +import com.jogamp.graph.curve.OutlineShape; +import com.jogamp.graph.curve.opengl.RegionRenderer; +import com.jogamp.graph.geom.opengl.SVertex; + +/** Demonstrate the rendering of multiple OutlineShapes + * into one region + * + */ +public class GPURegionGLListener02 extends GPURegionRendererListenerBase01 { + OutlineShape[] outlineShapes = new OutlineShape[2]; + + public GPURegionGLListener02 (int numpass, int fbosize, boolean debug, boolean trace) { + super(SVertex.factory(), numpass, debug, trace); + setMatrix(-20, 00, 0f, -50, fbosize); + } + + private void createTestOutline(){ + float offset = 0; + outlineShapes[0] = new OutlineShape(SVertex.factory()); + outlineShapes[0].addVertex(0.0f,-10.0f,true); + outlineShapes[0].addVertex(15.0f,-10.0f, true); + outlineShapes[0].addVertex(10.0f,5.0f, false); + outlineShapes[0].addVertex(15.0f,10.0f, true); + outlineShapes[0].addVertex(6.0f,15.0f, false); + outlineShapes[0].addVertex(5.0f,8.0f, false); + outlineShapes[0].addVertex(0.0f,10.0f,true); + outlineShapes[0].closeLastOutline(); + outlineShapes[0].addEmptyOutline(); + outlineShapes[0].addVertex(5.0f,-5.0f,true); + outlineShapes[0].addVertex(10.0f,-5.0f, false); + outlineShapes[0].addVertex(10.0f,0.0f, true); + outlineShapes[0].addVertex(5.0f,0.0f, false); + outlineShapes[0].closeLastOutline(); + + /** Same shape as above but without any off-curve vertices */ + outlineShapes[1] = new OutlineShape(SVertex.factory()); + offset = 30; + outlineShapes[1].addVertex(offset+0.0f,-10.0f, true); + outlineShapes[1].addVertex(offset+17.0f,-10.0f, true); + outlineShapes[1].addVertex(offset+11.0f,5.0f, true); + outlineShapes[1].addVertex(offset+16.0f,10.0f, true); + outlineShapes[1].addVertex(offset+7.0f,15.0f, true); + outlineShapes[1].addVertex(offset+6.0f,8.0f, true); + outlineShapes[1].addVertex(offset+0.0f,10.0f, true); + outlineShapes[1].closeLastOutline(); + outlineShapes[1].addEmptyOutline(); + outlineShapes[1].addVertex(offset+5.0f,0.0f, true); + outlineShapes[1].addVertex(offset+5.0f,-5.0f, true); + outlineShapes[1].addVertex(offset+10.0f,-5.0f, true); + outlineShapes[1].addVertex(offset+10.0f,0.0f, true); + outlineShapes[1].closeLastOutline(); + } + + public void init(GLAutoDrawable drawable) { + super.init(drawable); + + GL2ES2 gl = drawable.getGL().getGL2ES2(); + + final RegionRenderer regionRenderer = (RegionRenderer) getRenderer(); + + gl.setSwapInterval(1); + gl.glEnable(GL2ES2.GL_DEPTH_TEST); + regionRenderer.init(gl); + regionRenderer.setAlpha(gl, 1.0f); + regionRenderer.setColor(gl, 0.0f, 0.0f, 0.0f); + MSAATool.dump(drawable); + + createTestOutline(); + } + + public void display(GLAutoDrawable drawable) { + GL2ES2 gl = drawable.getGL().getGL2ES2(); + + gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); + gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); + + final RegionRenderer regionRenderer = (RegionRenderer) getRenderer(); + + regionRenderer.resetModelview(null); + regionRenderer.translate(null, getXTran(), getYTran(), getZoom()); + regionRenderer.rotate(gl, getAngle(), 0, 1, 0); + + regionRenderer.renderOutlineShapes(gl, outlineShapes, getPosition(), getTexSize()); + + } +} diff --git a/src/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo01.java b/src/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo01.java new file mode 100755 index 000000000..dbd5fe158 --- /dev/null +++ b/src/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo01.java @@ -0,0 +1,75 @@ +/** + * 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 com.jogamp.opengl.test.junit.graph.demos; + +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; + +import com.jogamp.graph.curve.Region; +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.util.Animator; + +/** Demonstrate the rendering of multiple outlines into one region/OutlineShape + * These Outlines are not necessary connected or contained. + * The output of this demo shows two identical shapes but the left one + * has some vertices with off-curve flag set to true, and the right allt he vertices + * are on the curve. Demos the Res. Independent Nurbs based Curve rendering + * + */ +public class GPURegionNewtDemo01 { + static final boolean DEBUG = false; + static final boolean TRACE = false; + + public static void main(String[] args) { + GLProfile.initSingleton(true); + GLProfile glp = GLProfile.getGL2ES2(); + GLCapabilities caps = new GLCapabilities(glp); + caps.setAlphaBits(4); + caps.setSampleBuffers(true); + caps.setNumSamples(4); // 2 samples is not enough .. + System.out.println("Requested: " + caps); + + GLWindow window = GLWindow.create(caps); + window.setPosition(10, 10); + window.setSize(800, 400); + window.setTitle("GPU Curve Region Newt Demo 01 - r2t0 msaa1"); + + GPURegionGLListener01 regionGLListener = new GPURegionGLListener01 (Region.SINGLE_PASS, 0, DEBUG, TRACE); + regionGLListener.attachInputListenerTo(window); + window.addGLEventListener(regionGLListener); + + window.enablePerfLog(true); + window.setVisible(true); + + //FPSAnimator animator = new FPSAnimator(60); + Animator animator = new Animator(); + animator.add(window); + animator.start(); + } +} diff --git a/src/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo02.java b/src/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo02.java new file mode 100644 index 000000000..7ffab59e3 --- /dev/null +++ b/src/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo02.java @@ -0,0 +1,75 @@ +/** + * 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 com.jogamp.opengl.test.junit.graph.demos; + +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; + +import com.jogamp.graph.curve.Region; +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.util.Animator; + +/** Demonstrate the rendering of multiple OutlineShapes + * into one region + * + */ +public class GPURegionNewtDemo02 { + static final boolean DEBUG = false; + static final boolean TRACE = false; + + public static void main(String[] args) { + GPURegionNewtDemo02 test = new GPURegionNewtDemo02(); + test.testMe(); + } + + public void testMe() { + GLProfile.initSingleton(true); + GLProfile glp = GLProfile.getGL2ES2(); + GLCapabilities caps = new GLCapabilities(glp); + caps.setAlphaBits(4); + System.out.println("Requested: " + caps); + + GLWindow window = GLWindow.create(caps); + window.setPosition(10, 10); + window.setSize(800, 400); + window.setTitle("GPU Curve Region Newt Demo 02 - r2t1 msaa0"); + + GPURegionGLListener02 regionGLListener = new GPURegionGLListener02 (Region.TWO_PASS, 1140, DEBUG, TRACE); + regionGLListener.attachInputListenerTo(window); + window.addGLEventListener(regionGLListener); + + window.enablePerfLog(true); + window.setVisible(true); + + //FPSAnimator animator = new FPSAnimator(60); + Animator animator = new Animator(); + animator.add(window); + animator.start(); + } +} diff --git a/src/demo/GPURegionRendererListenerBase01.java b/src/com/jogamp/opengl/test/junit/graph/demos/GPURegionRendererListenerBase01.java index 39a920656..eab5fc8eb 100644 --- a/src/demo/GPURegionRendererListenerBase01.java +++ b/src/com/jogamp/opengl/test/junit/graph/demos/GPURegionRendererListenerBase01.java @@ -25,7 +25,7 @@ * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. */ -package demo; +package com.jogamp.opengl.test.junit.graph.demos; import com.jogamp.graph.curve.OutlineShape; import com.jogamp.graph.curve.opengl.RegionRenderer; diff --git a/src/demo/GPURendererListenerBase01.java b/src/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java index e8dec4c01..622178bf2 100644 --- a/src/demo/GPURendererListenerBase01.java +++ b/src/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java @@ -25,7 +25,7 @@ * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. */ -package demo; +package com.jogamp.opengl.test.junit.graph.demos; import java.io.IOException; import java.io.PrintWriter; @@ -52,6 +52,7 @@ import com.jogamp.newt.opengl.GLWindow; * - 6/7: 2nd pass texture size * - 0/9: rotate * - v: toggle v-sync + * - s: screenshot */ public abstract class GPURendererListenerBase01 implements GLEventListener { private Screenshot screenshot; @@ -72,6 +73,7 @@ public abstract class GPURendererListenerBase01 implements GLEventListener { private int texSize = 400; boolean updateMatrix = true; + boolean ignoreInput = false; public GPURendererListenerBase01(Renderer renderer, boolean debug, boolean trace) { this.renderer = renderer; @@ -173,8 +175,21 @@ public abstract class GPURendererListenerBase01 implements GLEventListener { screenshot.surface2File(drawable, filename /*, exportAlpha */); } + int screenshot_num = 0; + + public void setIgnoreInput(boolean v) { + ignoreInput = v; + } + public boolean getIgnoreInput() { + return ignoreInput; + } + public class KeyAction implements KeyListener { public void keyPressed(KeyEvent arg0) { + if(ignoreInput) { + return; + } + if(arg0.getKeyCode() == KeyEvent.VK_1){ zoom(10); } @@ -224,6 +239,24 @@ public abstract class GPURendererListenerBase01 implements GLEventListener { }); } } + else if(arg0.getKeyCode() == KeyEvent.VK_S){ + rotate(-1); + if(null != autoDrawable) { + autoDrawable.invoke(false, new GLRunnable() { + public void run(GLAutoDrawable drawable) { + try { + final String type = ( 1 == renderer.getRenderType() ) ? "r2t0-msaa1" : "r2t1-msaa0" ; + printScreen(drawable, "./", "demo-"+type, "snap"+screenshot_num, false); + screenshot_num++; + } catch (GLException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + }); + } + } } public void keyTyped(KeyEvent arg0) {} public void keyReleased(KeyEvent arg0) {} diff --git a/src/com/jogamp/opengl/test/junit/graph/demos/GPUTextGLListener0A.java b/src/com/jogamp/opengl/test/junit/graph/demos/GPUTextGLListener0A.java new file mode 100644 index 000000000..7290246d1 --- /dev/null +++ b/src/com/jogamp/opengl/test/junit/graph/demos/GPUTextGLListener0A.java @@ -0,0 +1,61 @@ +/** + * 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 com.jogamp.opengl.test.junit.graph.demos; + + +import javax.media.opengl.GL2ES2; +import javax.media.opengl.GLAutoDrawable; + +import com.jogamp.graph.curve.opengl.TextRenderer; +import com.jogamp.graph.geom.opengl.SVertex; + +public class GPUTextGLListener0A extends GPUTextRendererListenerBase01 { + public GPUTextGLListener0A(int numpass, int fbosize, boolean debug, boolean trace) { + super(SVertex.factory(), numpass, debug, trace); + setMatrix(-400, -30, 0f, -500, fbosize); + } + + public void init(GLAutoDrawable drawable) { + super.init(drawable); + + GL2ES2 gl = drawable.getGL().getGL2ES2(); + + final TextRenderer textRenderer = (TextRenderer) getRenderer(); + + gl.setSwapInterval(1); + gl.glEnable(GL2ES2.GL_DEPTH_TEST); + textRenderer.init(gl); + textRenderer.setAlpha(gl, 1.0f); + textRenderer.setColor(gl, 0.0f, 0.0f, 0.0f); + //gl.glSampleCoverage(0.95f, false); + //gl.glEnable(GL2GL3.GL_SAMPLE_COVERAGE); // sample coverage doesn't really make a difference to lines + //gl.glEnable(GL2GL3.GL_SAMPLE_ALPHA_TO_COVERAGE); + //gl.glEnable(GL2GL3.GL_SAMPLE_ALPHA_TO_ONE); + MSAATool.dump(drawable); + } +} diff --git a/src/demo/GPUTextNewtDemo01.java b/src/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo01.java index 9a3067548..3739f28ea 100644 --- a/src/demo/GPUTextNewtDemo01.java +++ b/src/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo01.java @@ -25,17 +25,13 @@ * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. */ -package demo; +package com.jogamp.opengl.test.junit.graph.demos; -import javax.media.opengl.GL2ES2; -import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLProfile; import com.jogamp.graph.curve.Region; -import com.jogamp.graph.curve.opengl.TextRenderer; -import com.jogamp.graph.geom.opengl.SVertex; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opengl.util.Animator; @@ -44,13 +40,6 @@ public class GPUTextNewtDemo01 { static final boolean TRACE = false; public static void main(String[] args) { - GPUTextNewtDemo01 test = new GPUTextNewtDemo01(); - test.testMe(); - } - - TextGLListener textGLListener = null; - GLWindow window; - public void testMe() { GLProfile.initSingleton(true); GLProfile glp = GLProfile.getGL2ES2(); GLCapabilities caps = new GLCapabilities(glp); @@ -59,12 +48,12 @@ public class GPUTextNewtDemo01 { caps.setNumSamples(4); // 2 samples is not enough .. System.out.println("Requested: "+caps); - window = GLWindow.create(caps); + GLWindow window = GLWindow.create(caps); window.setPosition(10, 10); window.setSize(800, 400); window.setTitle("GPU Text Newt Demo 01 - r2t0 msaa1"); - textGLListener = new TextGLListener(); + GPUTextGLListener0A textGLListener = new GPUTextGLListener0A(Region.SINGLE_PASS, 0, DEBUG, TRACE); textGLListener.attachInputListenerTo(window); window.addGLEventListener(textGLListener); @@ -74,34 +63,5 @@ public class GPUTextNewtDemo01 { Animator animator = new Animator(); animator.add(window); animator.start(); - } - - private class TextGLListener extends GPUTextRendererListenerBase01 { - public TextGLListener() { - super(SVertex.factory(), Region.SINGLE_PASS, DEBUG, TRACE); - // FBO size unrelated with 1 pass - //setMatrix(-10, 10, 0f, -70, 0); - // setMatrix(-80, -30, 0f, -100, 0); - setMatrix(-400, -30, 0f, -500, 0); - } - - public void init(GLAutoDrawable drawable) { - super.init(drawable); - - GL2ES2 gl = drawable.getGL().getGL2ES2(); - - final TextRenderer textRenderer = (TextRenderer) getRenderer(); - - gl.setSwapInterval(1); - gl.glEnable(GL2ES2.GL_DEPTH_TEST); - textRenderer.init(gl); - textRenderer.setAlpha(gl, 1.0f); - textRenderer.setColor(gl, 0.0f, 0.0f, 0.0f); - //gl.glSampleCoverage(0.95f, false); - //gl.glEnable(GL2GL3.GL_SAMPLE_COVERAGE); // sample coverage doesn't really make a difference to lines - //gl.glEnable(GL2GL3.GL_SAMPLE_ALPHA_TO_COVERAGE); - //gl.glEnable(GL2GL3.GL_SAMPLE_ALPHA_TO_ONE); - MSAATool.dump(drawable); - } - } + } } diff --git a/src/demo/GPUTextNewtDemo02.java b/src/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java index 2078527dc..40c7d6ac4 100644 --- a/src/demo/GPUTextNewtDemo02.java +++ b/src/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java @@ -25,22 +25,19 @@ * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. */ -package demo; +package com.jogamp.opengl.test.junit.graph.demos; -import javax.media.opengl.GL; -import javax.media.opengl.GL3; -import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLProfile; import com.jogamp.graph.curve.Region; -import com.jogamp.graph.curve.opengl.TextRenderer; -import com.jogamp.graph.geom.opengl.SVertex; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opengl.util.Animator; public class GPUTextNewtDemo02 { /** + * FIXME: + * * If DEBUG is enabled: * * Caused by: javax.media.opengl.GLException: Thread[main-Display-X11_:0.0-1-EDT-1,5,main] glGetError() returned the following error codes after a call to glFramebufferRenderbuffer(<int> 0x8D40, <int> 0x1902, <int> 0x8D41, <int> 0x1): GL_INVALID_ENUM ( 1280 0x500), @@ -52,64 +49,28 @@ public class GPUTextNewtDemo02 { static final boolean TRACE = false; public static void main(String[] args) { - GPUTextNewtDemo02 test = new GPUTextNewtDemo02(); - test.testMe(); - } - - GLWindow window; - TextGLListener textGLListener = null; - - public void testMe() { GLProfile.initSingleton(true); - GLProfile glp = GLProfile.get(GLProfile.GL3); + GLProfile glp = GLProfile.getGL2ES2(); GLCapabilities caps = new GLCapabilities(glp); caps.setAlphaBits(4); System.out.println("Requested: "+caps); - window = GLWindow.create(caps); + GLWindow window = GLWindow.create(caps); window.setPosition(10, 10); window.setSize(800, 400); - window.setTitle("GPU Text Newt Demo 02 - r2t1 msaa0"); - textGLListener = new TextGLListener(); + + GPUTextGLListener0A textGLListener = new GPUTextGLListener0A(Region.TWO_PASS, window.getWidth()*3, DEBUG, TRACE); textGLListener.attachInputListenerTo(window); window.addGLEventListener(textGLListener); window.enablePerfLog(true); window.setVisible(true); - // FPSAnimator animator = new FPSAnimator(60); Animator animator = new Animator(); animator.add(window); animator.start(); - } - - private class TextGLListener extends GPUTextRendererListenerBase01 { - public TextGLListener() { - super(SVertex.factory(), Region.TWO_PASS, DEBUG, TRACE); - // FIXME: Rami will fix FBO size !! - // setMatrix(-10, 10, 0f, -100, 400); - // setMatrix(-80, -30, 0f, -100, window.getWidth()*3); - setMatrix(-400, -30, 0f, -500, window.getWidth()*3); - } - - public void init(GLAutoDrawable drawable) { - super.init(drawable); - - GL3 gl = drawable.getGL().getGL3(); - - final TextRenderer textRenderer = (TextRenderer) getRenderer(); - - gl.setSwapInterval(1); - gl.glEnable(GL3.GL_DEPTH_TEST); - textRenderer.init(gl); - textRenderer.setAlpha(gl, 1.0f); - textRenderer.setColor(gl, 0.0f, 0.0f, 0.0f); - gl.glDisable(GL.GL_MULTISAMPLE); // this state usually doesn't matter in driver - but document here: no MSAA - //gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL3.GL_NICEST); - MSAATool.dump(drawable); - } - } + } } diff --git a/src/demo/GPUTextRendererListenerBase01.java b/src/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java index d3f46ca20..909f68b85 100644 --- a/src/demo/GPUTextRendererListenerBase01.java +++ b/src/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java @@ -25,7 +25,7 @@ * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. */ -package demo; +package com.jogamp.opengl.test.junit.graph.demos; import java.io.IOException; import javax.media.opengl.GL; @@ -36,6 +36,7 @@ import javax.media.opengl.GLException; import com.jogamp.graph.curve.opengl.TextRenderer; import com.jogamp.graph.font.Font; import com.jogamp.graph.font.FontFactory; +import com.jogamp.graph.geom.AABBox; import com.jogamp.graph.geom.Vertex; import com.jogamp.newt.event.KeyEvent; import com.jogamp.newt.event.KeyListener; @@ -48,12 +49,14 @@ import com.jogamp.newt.opengl.GLWindow; * - 6/7: 2nd pass texture size * - 0/9: rotate * - v: toggle v-sync + * - s: screenshot * * Additional Keys: * - 3/4: font +/- - * - s: toogle draw 'font set' + * - h: toogle draw 'font set' * - f: toggle draw fps * - space: toggle font (ubuntu/java) + * - i: live input text input (CR ends it, backspace supported) */ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerBase01 { int fontSet = FontFactory.UBUNTU; @@ -67,7 +70,10 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB static final String text1 = "abcdefghijklmnopqrstuvwxyz\nABCDEFGHIJKLMNOPQRSTUVWXYZ\n0123456789.:,;(*!?/\\\")$%^&-+@~#<>{}[]"; static final String text2 = "The quick brown fox jumps over the lazy dog"; - + + StringBuffer userString = new StringBuffer(); + boolean userInput = false; + public GPUTextRendererListenerBase01(Vertex.Factory<? extends Vertex> factory, int mode, boolean debug, boolean trace) { super(TextRenderer.create(factory, mode), debug, trace); this.font = FontFactory.get(fontSet).getDefault(); @@ -100,7 +106,12 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB } if(drawFontSet) { textRenderer.resetModelview(null); - textRenderer.translate(gl, 0, height-50, -6000); + final AABBox box = font.getStringBounds(font.getName(), fontSize/4); + final int dx = width-(int)box.getWidth()-2; + final int dy = height-(int)box.getHeight()-2; + textRenderer.translate(gl, dx, dy, -6000); + textRenderer.renderString3D(gl, font, font.getName(), getPosition(), fontSize/4, getTexSize()); + textRenderer.translate(gl, -dx, -20, 0); textRenderer.renderString3D(gl, font, text1, getPosition(), fontSize, getTexSize()); } if(_drawFPS || drawFontSet) { @@ -113,7 +124,11 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB updateMatrix = false; } - textRenderer.renderString3D(gl, font, text2, getPosition(), fontSize, getTexSize()); + if(!userInput) { + textRenderer.renderString3D(gl, font, text2, getPosition(), fontSize, getTexSize()); + } else { + textRenderer.renderString3D(gl, font, userString.toString(), getPosition(), fontSize, getTexSize()); + } } public void fontIncr(int v) { @@ -132,6 +147,8 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB font = FontFactory.get(fontSet).get(family, stylebits); } + public boolean isUserInputMode() { return userInput; } + void dumpMatrix(boolean bbox) { System.err.println("Matrix: " + getXTran() + "/" + getYTran() + " x"+getZoom() + " @"+getAngle() +" fontSize "+fontSize); if(bbox) { @@ -166,13 +183,17 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB public class KeyAction implements KeyListener { public void keyPressed(KeyEvent arg0) { + if(userInput) { + return; + } + if(arg0.getKeyCode() == KeyEvent.VK_3){ fontIncr(10); } else if(arg0.getKeyCode() == KeyEvent.VK_4){ fontIncr(-10); } - else if(arg0.getKeyCode() == KeyEvent.VK_S) { + else if(arg0.getKeyCode() == KeyEvent.VK_H) { drawFontSet = !drawFontSet; System.err.println("Draw font set: "+drawFontSet); } @@ -183,8 +204,26 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB else if(arg0.getKeyCode() == KeyEvent.VK_SPACE) { nextFontSet(); } + else if(arg0.getKeyCode() == KeyEvent.VK_I){ + userInput = true; + setIgnoreInput(true); + } + } + public void keyTyped(KeyEvent arg0) { + if(userInput) { + char c = arg0.getKeyChar(); + + System.err.println(arg0); + if(c == 0x08) { + userString.deleteCharAt(userString.length()-1); + } else if(c == 0x0d) { + userInput = false; + setIgnoreInput(true); + } else { + userString.append(c); + } + } } - public void keyTyped(KeyEvent arg0) {} public void keyReleased(KeyEvent arg0) {} } }
\ No newline at end of file diff --git a/src/demo/MSAATool.java b/src/com/jogamp/opengl/test/junit/graph/demos/MSAATool.java index e357a3239..5975e096b 100644 --- a/src/demo/MSAATool.java +++ b/src/com/jogamp/opengl/test/junit/graph/demos/MSAATool.java @@ -25,7 +25,7 @@ * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. */ -package demo; +package com.jogamp.opengl.test.junit.graph.demos; import javax.media.opengl.GL2ES2; import javax.media.opengl.GL2GL3; diff --git a/src/demo/ReadBufferUtil.java b/src/com/jogamp/opengl/test/junit/graph/demos/ReadBufferUtil.java index 9a2da0d7e..172eef4fc 100644 --- a/src/demo/ReadBufferUtil.java +++ b/src/com/jogamp/opengl/test/junit/graph/demos/ReadBufferUtil.java @@ -26,7 +26,7 @@ * or implied, of JogAmp Community. */ -package demo; +package com.jogamp.opengl.test.junit.graph.demos; import com.jogamp.opengl.util.GLBuffers; import java.nio.*; diff --git a/src/demo/Screenshot.java b/src/com/jogamp/opengl/test/junit/graph/demos/Screenshot.java index 8e05b17ea..e0c304e49 100644 --- a/src/demo/Screenshot.java +++ b/src/com/jogamp/opengl/test/junit/graph/demos/Screenshot.java @@ -1,4 +1,4 @@ -package demo; +package com.jogamp.opengl.test.junit.graph.demos; import java.io.File; import java.io.IOException; diff --git a/src/demo/GPURegionNewtDemo01.java b/src/demo/GPURegionNewtDemo01.java deleted file mode 100755 index 676621692..000000000 --- a/src/demo/GPURegionNewtDemo01.java +++ /dev/null @@ -1,179 +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 demo; - -import javax.media.opengl.GL; -import javax.media.opengl.GL2ES2; -import javax.media.opengl.GLAutoDrawable; -import javax.media.opengl.GLCapabilities; -import javax.media.opengl.GLProfile; - -import com.jogamp.graph.curve.OutlineShape; -import com.jogamp.graph.curve.Region; -import com.jogamp.graph.curve.opengl.RegionRenderer; -import com.jogamp.graph.geom.opengl.SVertex; -import com.jogamp.newt.opengl.GLWindow; -import com.jogamp.opengl.util.Animator; - -/** Demonstrate the rendering of multiple outlines into one region/OutlineShape - * These Outlines are not necessary connected or contained. - * The output of this demo shows two identical shapes but the left one - * has some vertices with off-curve flag set to true, and the right allt he vertices - * are on the curve. Demos the Res. Independent Nurbs based Curve rendering - * - */ -public class GPURegionNewtDemo01 { - static final boolean DEBUG = false; - static final boolean TRACE = false; - - public static void main(String[] args) { - GPURegionNewtDemo01 test = new GPURegionNewtDemo01(); - test.testMe(); - } - - RegionGLListener regionGLListener = null; - GLWindow window; - - public void testMe() { - GLProfile.initSingleton(true); - GLProfile glp = GLProfile.getGL2ES2(); - GLCapabilities caps = new GLCapabilities(glp); - caps.setAlphaBits(4); - caps.setSampleBuffers(true); - caps.setNumSamples(4); // 2 samples is not enough .. - System.out.println("Requested: " + caps); - - GLWindow w = GLWindow.create(caps); - w.setPosition(10, 10); - w.setSize(800, 400); - w.setTitle("GPU Curve Region Newt Demo 01 - r2t0 msaa1"); - - regionGLListener = createRegionRendererListener(w); - - window.addGLEventListener(regionGLListener); - - window.enablePerfLog(true); - window.setVisible(true); - - //FPSAnimator animator = new FPSAnimator(60); - Animator animator = new Animator(); - animator.add(window); - animator.start(); - } - - public RegionGLListener createRegionRendererListener(GLWindow w) { - this.window = w; - - RegionGLListener l = new RegionGLListener(); - l.attachInputListenerTo(w); - - return l; - } - - public class RegionGLListener extends GPURegionRendererListenerBase01 { - OutlineShape outlineShape = null; - - public RegionGLListener() { - super(SVertex.factory(), Region.SINGLE_PASS, DEBUG, TRACE); - setMatrix(-20, 00, 0f, -50, 400); - } - - private void createTestOutline(){ - float offset = 0; - outlineShape = new OutlineShape(getRenderer().getFactory()); - outlineShape.addVertex(0.0f,-10.0f, true); - outlineShape.addVertex(15.0f,-10.0f, true); - outlineShape.addVertex(10.0f,5.0f, false); - outlineShape.addVertex(15.0f,10.0f, true); - outlineShape.addVertex(6.0f,15.0f, false); - outlineShape.addVertex(5.0f,8.0f, false); - outlineShape.addVertex(0.0f,10.0f,true); - outlineShape.closeLastOutline(); - outlineShape.addEmptyOutline(); - outlineShape.addVertex(5.0f,-5.0f,true); - outlineShape.addVertex(10.0f,-5.0f, false); - outlineShape.addVertex(10.0f,0.0f, true); - outlineShape.addVertex(5.0f,0.0f, false); - outlineShape.closeLastOutline(); - - /** Same shape as above but without any off-curve vertices */ - outlineShape.addEmptyOutline(); - offset = 30; - outlineShape.addVertex(offset+0.0f,-10.0f, true); - outlineShape.addVertex(offset+17.0f,-10.0f, true); - outlineShape.addVertex(offset+11.0f,5.0f, true); - outlineShape.addVertex(offset+16.0f,10.0f, true); - outlineShape.addVertex(offset+7.0f,15.0f, true); - outlineShape.addVertex(offset+6.0f,8.0f, true); - outlineShape.addVertex(offset+0.0f,10.0f, true); - outlineShape.closeLastOutline(); - outlineShape.addEmptyOutline(); - outlineShape.addVertex(offset+5.0f,0.0f, true); - outlineShape.addVertex(offset+5.0f,-5.0f, true); - outlineShape.addVertex(offset+10.0f,-5.0f, true); - outlineShape.addVertex(offset+10.0f,0.0f, true); - outlineShape.closeLastOutline(); - } - - public void init(GLAutoDrawable drawable) { - super.init(drawable); - - GL2ES2 gl = drawable.getGL().getGL2ES2(); - - final RegionRenderer regionRenderer = (RegionRenderer) getRenderer(); - - gl.setSwapInterval(1); - gl.glEnable(GL2ES2.GL_DEPTH_TEST); - regionRenderer.init(gl); - regionRenderer.setAlpha(gl, 1.0f); - regionRenderer.setColor(gl, 0.0f, 0.0f, 0.0f); - //gl.glSampleCoverage(0.95f, false); - //gl.glEnable(GL2GL3.GL_SAMPLE_COVERAGE); // sample coverage doesn't really make a difference to lines - //gl.glEnable(GL2GL3.GL_SAMPLE_ALPHA_TO_ONE); - MSAATool.dump(drawable); - - createTestOutline(); - } - - public void display(GLAutoDrawable drawable) { - GL2ES2 gl = drawable.getGL().getGL2ES2(); - - gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); - gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); - - final RegionRenderer regionRenderer = (RegionRenderer) getRenderer(); - - regionRenderer.resetModelview(null); - regionRenderer.translate(null, getXTran(), getYTran(), getZoom()); - regionRenderer.rotate(gl, getAngle(), 0, 1, 0); - - regionRenderer.renderOutlineShape(gl, outlineShape, getPosition(), getTexSize()); - } - } -} diff --git a/src/demo/GPURegionNewtDemo02.java b/src/demo/GPURegionNewtDemo02.java deleted file mode 100644 index 3d7b60574..000000000 --- a/src/demo/GPURegionNewtDemo02.java +++ /dev/null @@ -1,170 +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 demo; - -import javax.media.opengl.GL; -import javax.media.opengl.GL2ES2; -import javax.media.opengl.GLAutoDrawable; -import javax.media.opengl.GLCapabilities; -import javax.media.opengl.GLProfile; - -import com.jogamp.graph.curve.OutlineShape; -import com.jogamp.graph.curve.Region; -import com.jogamp.graph.curve.opengl.RegionRenderer; -import com.jogamp.graph.geom.opengl.SVertex; -import com.jogamp.newt.opengl.GLWindow; -import com.jogamp.opengl.util.Animator; - -/** Demonstrate the rendering of multiple OutlineShapes - * into one region - * - */ -public class GPURegionNewtDemo02 { - static final boolean DEBUG = false; - static final boolean TRACE = false; - - public static void main(String[] args) { - GPURegionNewtDemo02 test = new GPURegionNewtDemo02(); - test.testMe(); - } - - RegionGLListener regionGLListener = null; - GLWindow window; - public void testMe() { - GLProfile.initSingleton(true); - GLProfile glp = GLProfile.get(GLProfile.GL3); - GLCapabilities caps = new GLCapabilities(glp); - caps.setAlphaBits(4); - System.out.println("Requested: " + caps); - - GLWindow w = GLWindow.create(caps); - w.setPosition(10, 10); - w.setSize(800, 400); - w.setTitle("GPU Curve Region Newt Demo 02 - r2t1 msaa0"); - - regionGLListener = createRegionRendererListener(w); - window.addGLEventListener(regionGLListener); - - window.enablePerfLog(true); - window.setVisible(true); - - //FPSAnimator animator = new FPSAnimator(60); - Animator animator = new Animator(); - animator.add(window); - animator.start(); - } - - public RegionGLListener createRegionRendererListener(GLWindow w) { - this.window = w; - - RegionGLListener l = new RegionGLListener(); - l.attachInputListenerTo(w); - - return l; - } - - public class RegionGLListener extends GPURegionRendererListenerBase01 { - OutlineShape[] outlineShapes = new OutlineShape[2]; - - public RegionGLListener() { - super(SVertex.factory(), Region.TWO_PASS, DEBUG, TRACE); - setMatrix(-20, 00, 0f, -50, 1140); - } - - private void createTestOutline(){ - float offset = 0; - outlineShapes[0] = new OutlineShape(SVertex.factory()); - outlineShapes[0].addVertex(0.0f,-10.0f,true); - outlineShapes[0].addVertex(15.0f,-10.0f, true); - outlineShapes[0].addVertex(10.0f,5.0f, false); - outlineShapes[0].addVertex(15.0f,10.0f, true); - outlineShapes[0].addVertex(6.0f,15.0f, false); - outlineShapes[0].addVertex(5.0f,8.0f, false); - outlineShapes[0].addVertex(0.0f,10.0f,true); - outlineShapes[0].closeLastOutline(); - outlineShapes[0].addEmptyOutline(); - outlineShapes[0].addVertex(5.0f,-5.0f,true); - outlineShapes[0].addVertex(10.0f,-5.0f, false); - outlineShapes[0].addVertex(10.0f,0.0f, true); - outlineShapes[0].addVertex(5.0f,0.0f, false); - outlineShapes[0].closeLastOutline(); - - /** Same shape as above but without any off-curve vertices */ - outlineShapes[1] = new OutlineShape(SVertex.factory()); - offset = 30; - outlineShapes[1].addVertex(offset+0.0f,-10.0f, true); - outlineShapes[1].addVertex(offset+17.0f,-10.0f, true); - outlineShapes[1].addVertex(offset+11.0f,5.0f, true); - outlineShapes[1].addVertex(offset+16.0f,10.0f, true); - outlineShapes[1].addVertex(offset+7.0f,15.0f, true); - outlineShapes[1].addVertex(offset+6.0f,8.0f, true); - outlineShapes[1].addVertex(offset+0.0f,10.0f, true); - outlineShapes[1].closeLastOutline(); - outlineShapes[1].addEmptyOutline(); - outlineShapes[1].addVertex(offset+5.0f,0.0f, true); - outlineShapes[1].addVertex(offset+5.0f,-5.0f, true); - outlineShapes[1].addVertex(offset+10.0f,-5.0f, true); - outlineShapes[1].addVertex(offset+10.0f,0.0f, true); - outlineShapes[1].closeLastOutline(); - } - - public void init(GLAutoDrawable drawable) { - super.init(drawable); - - GL2ES2 gl = drawable.getGL().getGL2ES2(); - - final RegionRenderer regionRenderer = (RegionRenderer) getRenderer(); - - gl.setSwapInterval(1); - gl.glEnable(GL2ES2.GL_DEPTH_TEST); - regionRenderer.init(gl); - regionRenderer.setAlpha(gl, 1.0f); - regionRenderer.setColor(gl, 0.0f, 0.0f, 0.0f); - MSAATool.dump(drawable); - - createTestOutline(); - } - - public void display(GLAutoDrawable drawable) { - GL2ES2 gl = drawable.getGL().getGL2ES2(); - - gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); - gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); - - final RegionRenderer regionRenderer = (RegionRenderer) getRenderer(); - - regionRenderer.resetModelview(null); - regionRenderer.translate(null, getXTran(), getYTran(), getZoom()); - regionRenderer.rotate(gl, getAngle(), 0, 1, 0); - - regionRenderer.renderOutlineShapes(gl, outlineShapes, getPosition(), getTexSize()); - - } - } -} diff --git a/src/jogamp/graph/curve/opengl/TextRendererImpl01.java b/src/jogamp/graph/curve/opengl/TextRendererImpl01.java index aa3202805..cebe7a19e 100644 --- a/src/jogamp/graph/curve/opengl/TextRendererImpl01.java +++ b/src/jogamp/graph/curve/opengl/TextRendererImpl01.java @@ -176,11 +176,10 @@ public class TextRendererImpl01 extends TextRenderer { if(!isInitialized()){ throw new GLException("TextRendererImpl01: not initialized!"); } - String fontStrHash = getTextHashCode(font, str, fontSize); - GlyphString glyphString = strings.get(fontStrHash); + GlyphString glyphString = getCachedGlyphString(font, str, fontSize); if(null == glyphString) { glyphString = createString(gl, font, fontSize, str, mgl_sharpness.floatValue()); - strings.put(fontStrHash, glyphString); + addCachedGlyphString(font, str, fontSize, glyphString); } glyphString.renderString3D(pmvMatrix, vp_width, vp_height, texSize); diff --git a/src/jogamp/graph/curve/opengl/VBORegion2PES2.java b/src/jogamp/graph/curve/opengl/VBORegion2PES2.java index c424c4ddd..c7c370f6d 100644 --- a/src/jogamp/graph/curve/opengl/VBORegion2PES2.java +++ b/src/jogamp/graph/curve/opengl/VBORegion2PES2.java @@ -192,12 +192,12 @@ public class VBORegion2PES2 implements Region{ gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, t_vboIds.get(0)); - gl.glEnableVertexAttribArray(VERTEX_POS_INDX); - gl.glVertexAttribPointer(VERTEX_POS_INDX, 3, GL2ES2.GL_FLOAT, false, 3 * Buffers.SIZEOF_FLOAT, 0); + gl.glEnableVertexAttribArray(VERTEX_ATTR_IDX); + gl.glVertexAttribPointer(VERTEX_ATTR_IDX, 3, GL2ES2.GL_FLOAT, false, 3 * Buffers.SIZEOF_FLOAT, 0); gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, t_vboIds.get(1)); - gl.glEnableVertexAttribArray(TEX_COORD); - gl.glVertexAttribPointer(TEX_COORD, 2, GL2ES2.GL_FLOAT, false, 2 * Buffers.SIZEOF_FLOAT, 0); + gl.glEnableVertexAttribArray(TEXCOORD_ATTR_IDX); + gl.glVertexAttribPointer(TEXCOORD_ATTR_IDX, 2, GL2ES2.GL_FLOAT, false, 2 * Buffers.SIZEOF_FLOAT, 0); gl.glBindBuffer(GL2ES2.GL_ELEMENT_ARRAY_BUFFER, t_vboIds.get(2)); gl.glDrawElements(GL2ES2.GL_TRIANGLES, 2 * 3, GL2ES2.GL_UNSIGNED_SHORT, 0); @@ -332,12 +332,12 @@ public class VBORegion2PES2 implements Region{ GL2ES2 gl = context.getGL().getGL2ES2(); gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, vboIds.get(0)); - gl.glEnableVertexAttribArray(VERTEX_POS_INDX); - gl.glVertexAttribPointer(VERTEX_POS_INDX, 3, GL2ES2.GL_FLOAT, false, 3 * Buffers.SIZEOF_FLOAT, 0); + gl.glEnableVertexAttribArray(VERTEX_ATTR_IDX); + gl.glVertexAttribPointer(VERTEX_ATTR_IDX, 3, GL2ES2.GL_FLOAT, false, 3 * Buffers.SIZEOF_FLOAT, 0); gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, vboIds.get(1)); - gl.glEnableVertexAttribArray(TEX_COORD); - gl.glVertexAttribPointer(TEX_COORD, 2, GL2ES2.GL_FLOAT, false, 2 * Buffers.SIZEOF_FLOAT, 0); + gl.glEnableVertexAttribArray(TEXCOORD_ATTR_IDX); + gl.glVertexAttribPointer(TEXCOORD_ATTR_IDX, 2, GL2ES2.GL_FLOAT, false, 2 * Buffers.SIZEOF_FLOAT, 0); gl.glBindBuffer(GL2ES2.GL_ELEMENT_ARRAY_BUFFER, vboIds.get(2)); gl.glDrawElements(GL2ES2.GL_TRIANGLES, triangles.size() * 3, GL2ES2.GL_UNSIGNED_SHORT, 0); diff --git a/src/jogamp/graph/curve/opengl/VBORegionSPES2.java b/src/jogamp/graph/curve/opengl/VBORegionSPES2.java index f509dbd58..701549d46 100644 --- a/src/jogamp/graph/curve/opengl/VBORegionSPES2.java +++ b/src/jogamp/graph/curve/opengl/VBORegionSPES2.java @@ -134,12 +134,12 @@ public class VBORegionSPES2 implements Region{ GL2ES2 gl = context.getGL().getGL2ES2(); gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, vboIds.get(0)); - gl.glEnableVertexAttribArray(VERTEX_POS_INDX); - gl.glVertexAttribPointer(VERTEX_POS_INDX, 3, GL2ES2.GL_FLOAT, false, 3 * Buffers.SIZEOF_FLOAT, 0); + gl.glEnableVertexAttribArray(VERTEX_ATTR_IDX); + gl.glVertexAttribPointer(VERTEX_ATTR_IDX, 3, GL2ES2.GL_FLOAT, false, 3 * Buffers.SIZEOF_FLOAT, 0); gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, vboIds.get(1)); - gl.glEnableVertexAttribArray(TEX_COORD); - gl.glVertexAttribPointer(TEX_COORD, 2, GL2ES2.GL_FLOAT, false, 2 * Buffers.SIZEOF_FLOAT, 0); + gl.glEnableVertexAttribArray(TEXCOORD_ATTR_IDX); + gl.glVertexAttribPointer(TEXCOORD_ATTR_IDX, 2, GL2ES2.GL_FLOAT, false, 2 * Buffers.SIZEOF_FLOAT, 0); gl.glBindBuffer(GL2ES2.GL_ELEMENT_ARRAY_BUFFER, vboIds.get(2)); gl.glDrawElements(GL2ES2.GL_TRIANGLES, triangles.size() * 3, GL2ES2.GL_UNSIGNED_SHORT, 0); diff --git a/src/jogamp/graph/font/JavaFontLoader.java b/src/jogamp/graph/font/JavaFontLoader.java index 6769a691a..33505e797 100644 --- a/src/jogamp/graph/font/JavaFontLoader.java +++ b/src/jogamp/graph/font/JavaFontLoader.java @@ -58,8 +58,13 @@ public class JavaFontLoader implements FontSet { javaFontPath = System.getProperty("java.home") + "/lib/fonts/"; } + // FIXME: Add cache size to limit memory usage static final IntObjectHashMap fontMap = new IntObjectHashMap(); + static boolean is(int bits, int bit) { + return 0 != ( bits & bit ) ; + } + public Font getDefault() { return get(FAMILY_REGULAR, 0) ; // Sans Serif Regular } @@ -71,12 +76,13 @@ public class JavaFontLoader implements FontSet { } // 1st process Sans Serif (2 fonts) - if( 0 == ( style & STYLE_SERIF ) ) { - if( 0 != ( style & STYLE_BOLD ) ) { - font = abspath(availableFontFileNames[5]); + if( is(style, STYLE_SERIF) ) { + if( is(style, STYLE_BOLD) ) { + font = abspath(availableFontFileNames[5], family, style); } else { - font = abspath(availableFontFileNames[4]); + font = abspath(availableFontFileNames[4], family, style); } + fontMap.put( ( family << 8 ) | style, font ); return font; } @@ -86,24 +92,24 @@ public class JavaFontLoader implements FontSet { case FAMILY_MEDIUM: case FAMILY_CONDENSED: case FAMILY_REGULAR: - if( 0 != ( style & STYLE_BOLD ) ) { - if( 0 != ( style & STYLE_ITALIC ) ) { - font = abspath(availableFontFileNames[3]); + if( is(style, STYLE_BOLD) ) { + if( is(style, STYLE_ITALIC) ) { + font = abspath(availableFontFileNames[3], family, style); } else { - font = abspath(availableFontFileNames[2]); + font = abspath(availableFontFileNames[2], family, style); } - } else if( 0 != ( style & STYLE_ITALIC ) ) { - font = abspath(availableFontFileNames[1]); + } else if( is(style, STYLE_ITALIC) ) { + font = abspath(availableFontFileNames[1], family, style); } else { - font = abspath(availableFontFileNames[0]); + font = abspath(availableFontFileNames[0], family, style); } break; case FAMILY_MONOSPACED: - if( 0 != ( style & STYLE_BOLD ) ) { - font = abspath(availableFontFileNames[7]); + if( is(style, STYLE_BOLD) ) { + font = abspath(availableFontFileNames[7], family, style); } else { - font = abspath(availableFontFileNames[6]); + font = abspath(availableFontFileNames[6], family, style); } break; } @@ -111,8 +117,13 @@ public class JavaFontLoader implements FontSet { return font; } - Font abspath(String fname) { - return FontFactory.getFontConstr().create(javaFontPath+fname); + Font abspath(String fname, int family, int style) { + final Font f = FontFactory.getFontConstr().create(javaFontPath+fname); + if(null != f) { + fontMap.put( ( family << 8 ) | style, f ); + } + return f; + } } diff --git a/src/jogamp/graph/font/UbuntuFontLoader.java b/src/jogamp/graph/font/UbuntuFontLoader.java index 77d2cea03..e09ea85e5 100644 --- a/src/jogamp/graph/font/UbuntuFontLoader.java +++ b/src/jogamp/graph/font/UbuntuFontLoader.java @@ -27,6 +27,7 @@ */ package jogamp.graph.font; +import com.jogamp.common.util.IntObjectHashMap; import com.jogamp.graph.font.Font; import com.jogamp.graph.font.FontSet; import com.jogamp.graph.font.FontFactory; @@ -58,6 +59,9 @@ public class UbuntuFontLoader implements FontSet { private UbuntuFontLoader() { } + // FIXME: Add cache size to limit memory usage + static final IntObjectHashMap fontMap = new IntObjectHashMap(); + static boolean is(int bits, int bit) { return 0 != ( bits & bit ) ; } @@ -68,7 +72,10 @@ public class UbuntuFontLoader implements FontSet { public Font get(int family, int style) { - Font font = null; + Font font = (Font)fontMap.get( ( family << 8 ) | style ); + if (font != null) { + return font; + } switch (family) { case FAMILY_MONOSPACED: @@ -76,30 +83,30 @@ public class UbuntuFontLoader implements FontSet { case FAMILY_REGULAR: if( is(style, STYLE_BOLD) ) { if( is(style, STYLE_ITALIC) ) { - font = abspath(availableFontFileNames[3]); + font = abspath(availableFontFileNames[3], family, style); } else { - font = abspath(availableFontFileNames[2]); + font = abspath(availableFontFileNames[2], family, style); } } else if( is(style, STYLE_ITALIC) ) { - font = abspath(availableFontFileNames[1]); + font = abspath(availableFontFileNames[1], family, style); } else { - font = abspath(availableFontFileNames[0]); + font = abspath(availableFontFileNames[0], family, style); } break; case FAMILY_LIGHT: if( is(style, STYLE_ITALIC) ) { - font = abspath(availableFontFileNames[5]); + font = abspath(availableFontFileNames[5], family, style); } else { - font = abspath(availableFontFileNames[4]); + font = abspath(availableFontFileNames[4], family, style); } break; case FAMILY_MEDIUM: if( is(style, STYLE_ITALIC) ) { - font = abspath(availableFontFileNames[6]); + font = abspath(availableFontFileNames[6], family, style); } else { - font = abspath(availableFontFileNames[7]); + font = abspath(availableFontFileNames[7], family, style); } break; } @@ -110,6 +117,16 @@ public class UbuntuFontLoader implements FontSet { Font abspath(String fname) { return FontFactory.getFontConstr().create( Locator.getResource(UbuntuFontLoader.class, relPath+fname).getPath() ); + } + + Font abspath(String fname, int family, int style) { + final Font f = FontFactory.getFontConstr().create( + Locator.getResource(UbuntuFontLoader.class, relPath+fname).getPath() ); + if(null != f) { + fontMap.put( ( family << 8 ) | style, f ); + } + return f; } + } diff --git a/src/jogamp/graph/font/typecast/TypecastFont.java b/src/jogamp/graph/font/typecast/TypecastFont.java index 546eb85e3..0d018a314 100644 --- a/src/jogamp/graph/font/typecast/TypecastFont.java +++ b/src/jogamp/graph/font/typecast/TypecastFont.java @@ -49,6 +49,8 @@ class TypecastFont implements FontInt { TypecastHMetrics metrics; final CmapFormat cmapFormat; int cmapentries; + + // FIXME: Add cache size to limit memory usage ?? IntObjectHashMap char2Glyph; public TypecastFont(OTFontCollection fontset) { |